StelGuiItems.cpp   StelGuiItems.cpp 
skipping to change at line 26 skipping to change at line 26
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, U SA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, U SA.
*/ */
#include "StelApp.hpp" #include "StelApp.hpp"
#include "StelCore.hpp" #include "StelCore.hpp"
#include "StelProjector.hpp" #include "StelProjector.hpp"
#include "StelNavigator.hpp" #include "StelNavigator.hpp"
#include "StelGuiItems.hpp" #include "StelGuiItems.hpp"
#include "StelLocaleMgr.hpp" #include "StelLocaleMgr.hpp"
#include "StelMainGraphicsView.hpp"
#include "StelLocation.hpp" #include "StelLocation.hpp"
#include "StelGui.hpp"
#include "StelMovementMgr.hpp" #include "StelMovementMgr.hpp"
#include <QPainter> #include <QPainter>
#include <QGraphicsScene> #include <QGraphicsScene>
#include <QGraphicsView> #include <QGraphicsView>
#include <QGraphicsLineItem> #include <QGraphicsLineItem>
#include <QRectF> #include <QRectF>
#include <QDebug> #include <QDebug>
#include <QGraphicsSceneMouseEvent> #include <QGraphicsSceneMouseEvent>
#include <QGraphicsTextItem> #include <QGraphicsTextItem>
#include <QTimeLine> #include <QTimeLine>
#include <QMouseEvent> #include <QMouseEvent>
#include <QAction> #include <QAction>
#include <QRegExp> #include <QRegExp>
#include <QPixmapCache> #include <QPixmapCache>
#include <QProgressBar> #include <QProgressBar>
#include <QGraphicsWidget> #include <QGraphicsWidget>
#include <QGraphicsProxyWidget> #include <QGraphicsProxyWidget>
#include <QGraphicsLinearLayout>
StelButton::StelButton(QGraphicsItem* parent, const QPixmap& apixOn, const QPixmap& apixOff, StelButton::StelButton(QGraphicsItem* parent, const QPixmap& apixOn, const QPixmap& apixOff,
const QPixmap& apixHover, QAction* aaction, bool noBackgroun d) : const QPixmap& apixHover, QAction* aaction, bool noBackgroun d) :
QGraphicsPixmapItem(apixOff, parent), pixOn(apixOn), pixOff(apixOff), pixHover(apixHover), QGraphicsPixmapItem(apixOff, parent), pixOn(apixOn), pixOff(apixOff), pixHover(apixHover),
checked(false), action(aaction), noBckground(noBackg checked(ButtonStateOff), action(aaction), noBckgroun
round), opacity(1.), hoverOpacity(0.), redMode(false) d(noBackground), isTristate_(false),
opacity(1.), hoverOpacity(0.), redMode(false)
{ {
Q_ASSERT(!pixOn.isNull()); Q_ASSERT(!pixOn.isNull());
Q_ASSERT(!pixOff.isNull()); Q_ASSERT(!pixOff.isNull());
pixOnRed = StelGui::makeRed(pixOn); pixOnRed = StelButton::makeRed(pixOn);
pixOffRed = StelGui::makeRed(pixOff); pixOffRed = StelButton::makeRed(pixOff);
if (!pixHover.isNull()) if (!pixHover.isNull())
pixHoverRed = StelGui::makeRed(pixHover); pixHoverRed = StelButton::makeRed(pixHover);
if (!pixBackground.isNull()) if (!pixBackground.isNull())
pixBackgroundRed = StelGui::makeRed(pixBackground); pixBackgroundRed = StelButton::makeRed(pixBackground);
setShapeMode(QGraphicsPixmapItem::BoundingRectShape); setShapeMode(QGraphicsPixmapItem::BoundingRectShape);
setAcceptsHoverEvents(true); setAcceptsHoverEvents(true);
timeLine = new QTimeLine(250, this); timeLine = new QTimeLine(250, this);
timeLine->setCurveShape(QTimeLine::EaseOutCurve); timeLine->setCurveShape(QTimeLine::EaseOutCurve);
connect(timeLine, SIGNAL(valueChanged(qreal)), this, SLOT(animValueC hanged(qreal))); connect(timeLine, SIGNAL(valueChanged(qreal)), this, SLOT(animValueC hanged(qreal)));
if (action!=NULL) if (action!=NULL)
{ {
QObject::connect(action, SIGNAL(toggled(bool)), this, SLOT(s etChecked(bool))); QObject::connect(action, SIGNAL(toggled(bool)), this, SLOT(s etChecked(bool)));
skipping to change at line 84 skipping to change at line 84
setChecked(action->isChecked()); setChecked(action->isChecked());
QObject::connect(this, SIGNAL(toggled(bool)), action , SLOT(setChecked(bool))); QObject::connect(this, SIGNAL(toggled(bool)), action , SLOT(setChecked(bool)));
} }
else else
{ {
QObject::connect(this, SIGNAL(triggered()), action, SLOT(trigger())); QObject::connect(this, SIGNAL(triggered()), action, SLOT(trigger()));
} }
} }
} }
StelButton::StelButton(QGraphicsItem* parent, const QPixmap& apixOn, const
QPixmap& apixOff, const QPixmap& apixNoChange,
const QPixmap& apixHover, QAction* aaction, bool noBackgroun
d, bool isTristate) :
QGraphicsPixmapItem(apixOff, parent), pixOn(apixOn),
pixOff(apixOff), pixNoChange(apixNoChange), pixHover(apixHover),
checked(ButtonStateOff), action(aaction), noBckgroun
d(noBackground), isTristate_(isTristate),
opacity(1.), hoverOpacity(0.), redMode(false)
{
Q_ASSERT(!pixOn.isNull());
Q_ASSERT(!pixOff.isNull());
pixOnRed = StelButton::makeRed(pixOn);
pixOffRed = StelButton::makeRed(pixOff);
if (isTristate_) {
Q_ASSERT(!pixNoChange.isNull());
pixNoChangeRed = StelButton::makeRed(pixNoChange);
}
if (!pixHover.isNull())
pixHoverRed = StelButton::makeRed(pixHover);
if (!pixBackground.isNull())
pixBackgroundRed = StelButton::makeRed(pixBackground);
setShapeMode(QGraphicsPixmapItem::BoundingRectShape);
setAcceptsHoverEvents(true);
timeLine = new QTimeLine(250, this);
timeLine->setCurveShape(QTimeLine::EaseOutCurve);
connect(timeLine, SIGNAL(valueChanged(qreal)), this, SLOT(animValueC
hanged(qreal)));
if (action!=NULL)
{
QObject::connect(action, SIGNAL(toggled(bool)), this, SLOT(s
etChecked(bool)));
if (action->isCheckable())
{
setChecked(action->isChecked());
QObject::connect(this, SIGNAL(toggled(bool)), action
, SLOT(setChecked(bool)));
}
else
{
QObject::connect(this, SIGNAL(triggered()), action,
SLOT(trigger()));
}
}
}
int StelButton::toggleChecked(int checked) {
if (!isTristate_)
checked = !!!checked;
else {
if (++checked > ButtonStateNoChange)
checked = ButtonStateOff;
}
return checked;
}
void StelButton::mousePressEvent(QGraphicsSceneMouseEvent* event) void StelButton::mousePressEvent(QGraphicsSceneMouseEvent* event)
{ {
QGraphicsItem::mousePressEvent(event); QGraphicsItem::mousePressEvent(event);
event->accept(); event->accept();
setChecked(!checked); setChecked(toggleChecked(checked));
emit(toggled(checked)); emit(toggled(checked));
emit(triggered()); emit(triggered());
} }
void StelButton::hoverEnterEvent(QGraphicsSceneHoverEvent* event) void StelButton::hoverEnterEvent(QGraphicsSceneHoverEvent* event)
{ {
timeLine->setDirection(QTimeLine::Forward); timeLine->setDirection(QTimeLine::Forward);
if (timeLine->state()!=QTimeLine::Running) if (timeLine->state()!=QTimeLine::Running)
timeLine->start(); timeLine->start();
skipping to change at line 110 skipping to change at line 160
} }
void StelButton::hoverLeaveEvent(QGraphicsSceneHoverEvent* event) void StelButton::hoverLeaveEvent(QGraphicsSceneHoverEvent* event)
{ {
timeLine->setDirection(QTimeLine::Backward); timeLine->setDirection(QTimeLine::Backward);
if (timeLine->state()!=QTimeLine::Running) if (timeLine->state()!=QTimeLine::Running)
timeLine->start(); timeLine->start();
emit(hoverChanged(false)); emit(hoverChanged(false));
} }
void StelButton::mouseReleaseEvent(QGraphicsSceneMouseEvent * event)
{
if (action!=NULL && !action->isCheckable())
setChecked(toggleChecked(checked));
}
void StelButton::updateIcon() void StelButton::updateIcon()
{ {
if (opacity<0.) if (opacity<0.)
opacity=0; opacity=0;
QPixmap pix(pixOn.size()); QPixmap pix(pixOn.size());
pix.fill(QColor(0,0,0,0)); pix.fill(QColor(0,0,0,0));
QPainter painter(&pix); QPainter painter(&pix);
painter.setOpacity(opacity); painter.setOpacity(opacity);
if (!pixBackground.isNull() && noBckground==false) if (!pixBackground.isNull() && noBckground==false)
painter.drawPixmap(0,0, redMode ? pixBackgroundRed : pixBack ground); painter.drawPixmap(0,0, redMode ? pixBackgroundRed : pixBack ground);
painter.drawPixmap(0,0, redMode ? (checked ? pixOnRed : pixOffRed) : painter.drawPixmap(0, 0,
(checked ? pixOn : pixOff)); (isTristate_ && checked == ButtonStateNoChange) ? (redMode ?
pixNoChangeRed : pixNoChange) :
(checked == ButtonStateOn) ? (redMode ? pixOnRed : pixOn) :
/* (checked == ButtonStateOff) ? */ (redMode ? pixOffRed : p
ixOff));
if (hoverOpacity>0) if (hoverOpacity>0)
{ {
painter.setOpacity(hoverOpacity*opacity); painter.setOpacity(hoverOpacity*opacity);
painter.drawPixmap(0,0, redMode ? pixHoverRed : pixHover); painter.drawPixmap(0,0, redMode ? pixHoverRed : pixHover);
} }
setPixmap(pix); setPixmap(pix);
} }
void StelButton::animValueChanged(qreal value) void StelButton::animValueChanged(qreal value)
{ {
hoverOpacity = value; hoverOpacity = value;
updateIcon(); updateIcon();
} }
void StelButton::setChecked(bool b) void StelButton::setChecked(int b)
{ {
checked=b; checked=b;
updateIcon(); updateIcon();
} }
QPixmap StelButton::makeRed(const QPixmap& p)
{
QImage im = p.toImage().convertToFormat(QImage::Format_ARGB32);
Q_ASSERT(im.format()==QImage::Format_ARGB32);
QRgb* bits = (QRgb*)im.bits();
const QRgb* stop = bits+im.width()*im.height();
do
{
*bits = qRgba(qRed(*bits), (int)(0.2*qGreen(*bits)), (int)(0
.2*qBlue(*bits)), qAlpha(*bits));
++bits;
}
while (bits!=stop);
return QPixmap::fromImage(im);
}
LeftStelBar::LeftStelBar(QGraphicsItem* parent) : QGraphicsItem(parent) LeftStelBar::LeftStelBar(QGraphicsItem* parent) : QGraphicsItem(parent)
{ {
// Create the help label // Create the help label
helpLabel = new QGraphicsSimpleTextItem("", this); helpLabel = new QGraphicsSimpleTextItem("", this);
QFont font("DejaVuSans"); QFont font("DejaVuSans");
font.setPixelSize(14); font.setPixelSize(13);
helpLabel->setFont(font); helpLabel->setFont(font);
helpLabel->setBrush(QBrush(QColor::fromRgbF(1,1,1,1))); helpLabel->setBrush(QBrush(QColor::fromRgbF(1,1,1,1)));
} }
LeftStelBar::~LeftStelBar() LeftStelBar::~LeftStelBar()
{ {
} }
void LeftStelBar::addButton(StelButton* button) void LeftStelBar::addButton(StelButton* button)
{ {
double posY = 0; double posY = 0;
if (QGraphicsItem::children().size()!=0) if (QGraphicsItem::children().size()!=0)
{ {
const QRectF& r = childrenBoundingRect(); const QRectF& r = childrenBoundingRect();
posY += r.bottom()-1; posY += r.bottom()-1;
} }
button->setParentItem(this); button->setParentItem(this);
button->prepareGeometryChange(); // could possibly be removed when q t 4.6 become stable
button->setPos(0.5, posY+10.5); button->setPos(0.5, posY+10.5);
connect(button, SIGNAL(hoverChanged(bool)), this, SLOT(buttonHoverCh anged(bool))); connect(button, SIGNAL(hoverChanged(bool)), this, SLOT(buttonHoverCh anged(bool)));
} }
void LeftStelBar::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) void LeftStelBar::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
{ {
} }
QRectF LeftStelBar::boundingRect() const QRectF LeftStelBar::boundingRect() const
skipping to change at line 254 skipping to change at line 330
// The text is dummy just for testing // The text is dummy just for testing
datetime = new QGraphicsSimpleTextItem("2008-02-06 17:33", this); datetime = new QGraphicsSimpleTextItem("2008-02-06 17:33", this);
location = new QGraphicsSimpleTextItem("Munich, Earth, 500m", this); location = new QGraphicsSimpleTextItem("Munich, Earth, 500m", this);
fov = new QGraphicsSimpleTextItem("FOV 43.45", this); fov = new QGraphicsSimpleTextItem("FOV 43.45", this);
fps = new QGraphicsSimpleTextItem("43.2 FPS", this); fps = new QGraphicsSimpleTextItem("43.2 FPS", this);
// Create the help label // Create the help label
helpLabel = new QGraphicsSimpleTextItem("", this); helpLabel = new QGraphicsSimpleTextItem("", this);
QFont font2("DejaVuSans"); QFont font2("DejaVuSans");
font2.setPixelSize(14); font2.setPixelSize(13);
helpLabel->setFont(font2); helpLabel->setFont(font2);
helpLabel->setBrush(QBrush(QColor::fromRgbF(1,1,1,1))); helpLabel->setBrush(QBrush(QColor::fromRgbF(1,1,1,1)));
QColor color = QColor::fromRgbF(1,1,1,1); QColor color = QColor::fromRgbF(1,1,1,1);
setColor(color); setColor(color);
datetime->setFont(font); datetime->setFont(font);
location->setFont(font); location->setFont(font);
fov->setFont(font); fov->setFont(font);
fps->setFont(font); fps->setFont(font);
skipping to change at line 352 skipping to change at line 428
// Set the margin at the left and right of a button group in pixels // Set the margin at the left and right of a button group in pixels
void BottomStelBar::setGroupMargin(const QString& groupName, int left, int right) void BottomStelBar::setGroupMargin(const QString& groupName, int left, int right)
{ {
if (!buttonGroups.contains(groupName)) if (!buttonGroups.contains(groupName))
return; return;
buttonGroups[groupName].leftMargin=left; buttonGroups[groupName].leftMargin=left;
buttonGroups[groupName].rightMargin=right; buttonGroups[groupName].rightMargin=right;
updateButtonsGroups(); updateButtonsGroups();
} }
//! Change the background of a group
void BottomStelBar::setGroupBackground(const QString& groupName, const QPix
map& pixLeft,
const QPixmap& pixRight, co
nst QPixmap& pixMiddle,
const QPixmap& pixSingle){
if (!buttonGroups.contains(groupName))
return;
buttonGroups[groupName].pixBackgroundLeft = new QPixmap(pixLeft);
buttonGroups[groupName].pixBackgroundRight = new QPixmap(pixRight);
buttonGroups[groupName].pixBackgroundMiddle = new QPixmap(pixMiddle)
;
buttonGroups[groupName].pixBackgroundSingle = new QPixmap(pixSingle)
;
updateButtonsGroups();
}
QRectF BottomStelBar::getButtonsBoundingRect() const QRectF BottomStelBar::getButtonsBoundingRect() const
{ {
// Re-use original Qt code, just remove the help label // Re-use original Qt code, just remove the help label
QRectF childRect; QRectF childRect;
bool hasBtn = false; bool hasBtn = false;
foreach (QGraphicsItem *child, QGraphicsItem::children()) foreach (QGraphicsItem *child, QGraphicsItem::children())
{ {
if (qgraphicsitem_cast<StelButton*>(child)==0) if (qgraphicsitem_cast<StelButton*>(child)==0)
continue; continue;
hasBtn = true; hasBtn = true;
skipping to change at line 385 skipping to change at line 477
double x=0; double x=0;
double y = datetime->boundingRect().height()+3; double y = datetime->boundingRect().height()+3;
for (QMap<QString, ButtonGroup >::iterator iter=buttonGroups.begin() ;iter!=buttonGroups.end();++iter) for (QMap<QString, ButtonGroup >::iterator iter=buttonGroups.begin() ;iter!=buttonGroups.end();++iter)
{ {
if (iter.value().elems.empty()) if (iter.value().elems.empty())
continue; continue;
x+=iter.value().leftMargin; x+=iter.value().leftMargin;
int n=0; int n=0;
foreach (StelButton* b, iter.value().elems) foreach (StelButton* b, iter.value().elems)
{ {
// We check if the group has its own background if n
ot the case
// We apply a default background.
if (n==0) if (n==0)
{ {
if (iter.value().elems.size()==1) if (iter.value().elems.size()==1)
b->pixBackground = pixBackgroundSing {
le; if (iter.value().pixBackgroundSingle
== NULL)
b->pixBackground = pixBackgr
oundSingle;
else
b->pixBackground = *(iter.va
lue().pixBackgroundSingle);
}
else else
b->pixBackground = pixBackgroundLeft {
; if (iter.value().pixBackgroundLeft =
= NULL)
b->pixBackground = pixBackgr
oundLeft;
else
b->pixBackground = *(iter.va
lue().pixBackgroundLeft);
}
} }
else if (n==iter.value().elems.size()-1) else if (n==iter.value().elems.size()-1)
{ {
if (iter.value().elems.size()!=1) if (iter.value().elems.size()!=1)
b->pixBackground = pixBackgroundSing {
le; if (iter.value().pixBackgroundSingle
b->pixBackground = pixBackgroundRight; == NULL)
b->pixBackground = pixBackgr
oundSingle;
else
b->pixBackground = *(iter.va
lue().pixBackgroundSingle);
}
if (iter.value().pixBackgroundRight == NULL)
b->pixBackground = pixBackgroundRigh
t;
else
b->pixBackground = *(iter.value().pi
xBackgroundRight);
} }
else else
{ {
b->pixBackground = pixBackgroundMiddle; if (iter.value().pixBackgroundMiddle == NULL
)
b->pixBackground = pixBackgroundMidd
le;
else
b->pixBackground = *(iter.value().pi
xBackgroundMiddle);
} }
// Update the button pixmap // Update the button pixmap
b->animValueChanged(0.); b->animValueChanged(0.);
b->setPos(x, y); b->setPos(x, y);
x+=b->pixOn.width(); x+=b->pixOn.width();
++n; ++n;
} }
x+=iter.value().rightMargin; x+=iter.value().rightMargin;
} }
updateText(); updateText(true);
} }
// Make sure to avoid any change if not necessary to avoid triggering usele ss redraw // Make sure to avoid any change if not necessary to avoid triggering usele ss redraw
void BottomStelBar::updateText() void BottomStelBar::updateText(bool updatePos)
{ {
bool updatePos = false;
StelCore* core = StelApp::getInstance().getCore(); StelCore* core = StelApp::getInstance().getCore();
double jd = core->getNavigator()->getJDay(); double jd = core->getNavigator()->getJDay();
QString newDate = flagShowTime ? StelApp::getInstance().getLocaleMgr ().getPrintableDateLocal(jd) +" " QString newDate = flagShowTime ? StelApp::getInstance().getLocaleMgr ().getPrintableDateLocal(jd) +" "
+StelApp::getInstance().getLocaleMgr().getPrintableT imeLocal(jd) : " "; +StelApp::getInstance().getLocaleMgr().getPrintableT imeLocal(jd) : " ";
if (datetime->text()!=newDate) if (datetime->text()!=newDate)
{ {
updatePos = true; updatePos = true;
datetime->setText(newDate); datetime->setText(newDate);
} }
skipping to change at line 579 skipping to change at line 693
setPath(newPath); setPath(newPath);
} }
void StelBarsPath::setBackgroundOpacity(double opacity) void StelBarsPath::setBackgroundOpacity(double opacity)
{ {
setBrush(QBrush(QColor::fromRgbF(0.22, 0.22, 0.23, opacity))); setBrush(QBrush(QColor::fromRgbF(0.22, 0.22, 0.23, opacity)));
} }
StelProgressBarMgr::StelProgressBarMgr(QGraphicsItem* parent) StelProgressBarMgr::StelProgressBarMgr(QGraphicsItem* parent)
{ {
setLayout(new QGraphicsLinearLayout(Qt::Vertical));
} }
/*
void StelProgressBarMgr::paint(QPainter *painter, const QStyleOptionGraphic
sItem *option, QWidget *widget)
{
// Do nothing. Just paint the child widgets
}
QRectF StelProgressBarMgr::boundingRect() const QRectF StelProgressBarMgr::boundingRect() const
{ {
if (QGraphicsItem::children().size()==0) if (QGraphicsItem::children().size()==0)
return QRectF(); return QRectF();
const QRectF& r = childrenBoundingRect(); const QRectF& r = childrenBoundingRect();
return QRectF(0, 0, r.width()-1, r.height()-1); return QRectF(0, 0, r.width()-1, r.height()-1);
} }*/
QProgressBar* StelProgressBarMgr::addProgressBar() QProgressBar* StelProgressBarMgr::addProgressBar()
{ {
QProgressBar* pb = new QProgressBar(); QProgressBar* pb = new QProgressBar();
pb->setFixedHeight(15); pb->setFixedHeight(15);
pb->setFixedWidth(250); pb->setFixedWidth(250);
pb->setTextVisible(true); pb->setTextVisible(true);
pb->setValue(66); pb->setValue(66);
QGraphicsProxyWidget* pbProxy = new QGraphicsProxyWidget(); QGraphicsProxyWidget* pbProxy = new QGraphicsProxyWidget();
pbProxy->setWidget(pb); pbProxy->setWidget(pb);
pbProxy->setParentItem(this);
pbProxy->setCacheMode(QGraphicsItem::DeviceCoordinateCache); pbProxy->setCacheMode(QGraphicsItem::DeviceCoordinateCache);
pbProxy->setZValue(150); pbProxy->setZValue(150);
updateBarsPositions(); static_cast<QGraphicsLinearLayout*>(layout())->addItem(pbProxy);
connect(pbProxy, SIGNAL(destroyed(QObject*)), this, SLOT(oneDestroye
d(QObject*)));
return pb; return pb;
} }
void StelProgressBarMgr::updateBarsPositions()
{
int y=0;
foreach(QGraphicsItem* item, childItems())
{
item->setPos(0, y);
y+=18;
}
}
void StelProgressBarMgr::oneDestroyed(QObject* obj)
{
updateBarsPositions();
}
CornerButtons::CornerButtons(QGraphicsItem* parent) : lastOpacity(10) CornerButtons::CornerButtons(QGraphicsItem* parent) : lastOpacity(10)
{ {
} }
void CornerButtons::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) void CornerButtons::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{ {
// Do nothing. Just paint the child widgets // Do nothing. Just paint the child widgets
} }
QRectF CornerButtons::boundingRect() const QRectF CornerButtons::boundingRect() const
 End of changes. 31 change blocks. 
52 lines changed or deleted 169 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/