StelDialog.cpp   StelDialog.cpp 
skipping to change at line 21 skipping to change at line 21
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
*/ */
#include "StelDialog.hpp" #include "StelDialog.hpp"
#include "StelMainGraphicsView.hpp" #include "StelMainView.hpp"
#include "StelGui.hpp"
#include "StelApp.hpp"
#include <QDebug> #include <QDebug>
#include <QDialog> #include <QDialog>
#include <QGraphicsProxyWidget> #include <QGraphicsProxyWidget>
#include <QStyleOptionGraphicsItem> #include <QStyleOptionGraphicsItem>
#include <QSettings>
class CustomProxy : public QGraphicsProxyWidget class CustomProxy : public QGraphicsProxyWidget
{ {
public: public:
CustomProxy(QGraphicsItem *parent = 0, Qt::WindowFlags wFlag s = 0) : QGraphicsProxyWidget(parent, wFlags) CustomProxy(QGraphicsItem *parent = 0, Qt::WindowFlags wFlag s = 0) : QGraphicsProxyWidget(parent, wFlags)
{ {
setFocusPolicy(Qt::StrongFocus); setFocusPolicy(Qt::StrongFocus);
} }
//! Reimplement this method to add windows decorations. Curr ently there are invisible 2 px decorations //! Reimplement this method to add windows decorations. Curr ently there are invisible 2 px decorations
void paintWindowFrame(QPainter*, const QStyleOptionGraphicsI tem*, QWidget*) void paintWindowFrame(QPainter*, const QStyleOptionGraphicsI tem*, QWidget*)
skipping to change at line 48 skipping to change at line 51
/* QStyleOptionTitleBar bar; /* QStyleOptionTitleBar bar;
initStyleOption(&bar); initStyleOption(&bar);
bar.subControls = QStyle::SC_TitleBarCloseButton; bar.subControls = QStyle::SC_TitleBarCloseButton;
qWarning() << style()->subControlRect(QStyle::CC_Tit leBar, &bar, QStyle::SC_TitleBarCloseButton); qWarning() << style()->subControlRect(QStyle::CC_Tit leBar, &bar, QStyle::SC_TitleBarCloseButton);
QGraphicsProxyWidget::paintWindowFrame(painter, opti on, widget);*/ QGraphicsProxyWidget::paintWindowFrame(painter, opti on, widget);*/
} }
protected: protected:
virtual bool event(QEvent* event) virtual bool event(QEvent* event)
{ {
if (event->type()==QEvent::WindowDeactivate) if (StelApp::getInstance().getSettings()->value("gui /flag_use_window_transparency", true).toBool())
{ {
widget()->setWindowOpacity(0.4); switch (event->type())
} {
if (event->type()==QEvent::WindowActivate) case QEvent::WindowDeactivate:
{ widget()->setWindowOpacity(0
widget()->setWindowOpacity(0.9); .4);
break;
case QEvent::WindowActivate:
case QEvent::GrabMouse:
widget()->setWindowOpacity(0
.9);
break;
default:
break;
}
} }
return QGraphicsProxyWidget::event(event); return QGraphicsProxyWidget::event(event);
} }
}; };
StelDialog::StelDialog(QObject* parent) : QObject(parent), dialog(NULL) StelDialog::StelDialog(QObject* parent)
: QObject(parent)
, dialog(NULL)
, proxy(NULL)
{ {
if (parent == NULL)
setParent(StelMainView::getInstance().getGuiWidget());
} }
StelDialog::~StelDialog() StelDialog::~StelDialog()
{ {
} }
void StelDialog::close() void StelDialog::close()
{ {
setVisible(false); setVisible(false);
StelMainGraphicsView::getInstance().scene()->setActiveWindow(0);
((QGraphicsWidget*)StelMainGraphicsView::getInstance().getStelAppGra
phicsWidget())->setFocus(Qt::OtherFocusReason);
} }
bool StelDialog::visible() const bool StelDialog::visible() const
{ {
return dialog!=NULL && dialog->isVisible(); return dialog!=NULL && dialog->isVisible();
} }
void StelDialog::setVisible(bool v) void StelDialog::setVisible(bool v)
{ {
if (v) if (v)
{ {
QSize screenSize = StelMainGraphicsView::getInstance().size( ); QSize screenSize = StelMainView::getInstance().size();
if (dialog) if (dialog)
{ {
dialog->show(); dialog->show();
StelMainGraphicsView::getInstance().scene()->setActi veWindow(proxy); StelMainView::getInstance().scene()->setActiveWindow (proxy);
// If the main window has been resized, it is possib le the dialog // If the main window has been resized, it is possib le the dialog
// will be off screen. Check for this and move it t o a visible // will be off screen. Check for this and move it t o a visible
// position if necessary // position if necessary
QPointF newPos = proxy->pos(); QPointF newPos = proxy->pos();
if (newPos.x()>=screenSize.width()) if (newPos.x()>=screenSize.width())
newPos.setX(screenSize.width() - dialog->siz e().width()); newPos.setX(screenSize.width() - dialog->siz e().width());
if (newPos.y()>=screenSize.height()) if (newPos.y()>=screenSize.height())
newPos.setY(screenSize.height() - dialog->si ze().height()); newPos.setY(screenSize.height() - dialog->si ze().height());
if (newPos != dialog->pos()) if (newPos != dialog->pos())
proxy->setPos(newPos); proxy->setPos(newPos);
proxy->setFocus(); proxy->setFocus();
return; return;
} }
QGraphicsWidget* parent = qobject_cast<QGraphicsWidget*>(thi
s->parent());
dialog = new QDialog(NULL); dialog = new QDialog(NULL);
// dialog->setParent(parent);
StelGui* gui = dynamic_cast<StelGui*>(StelApp::getInstance()
.getGui());
Q_ASSERT(gui);
//dialog->setAttribute(Qt::WA_OpaquePaintEvent, true); //dialog->setAttribute(Qt::WA_OpaquePaintEvent, true);
connect(dialog, SIGNAL(rejected()), this, SLOT(close())); connect(dialog, SIGNAL(rejected()), this, SLOT(close()));
createDialogContent(); createDialogContent();
dialog->setStyleSheet(gui->getStelStyle().qtStyleSheet);
proxy = new CustomProxy(NULL, Qt::Tool); proxy = new CustomProxy(parent, Qt::Tool);
proxy->setWidget(dialog); proxy->setWidget(dialog);
QSizeF size = proxy->size(); QSizeF size = proxy->size();
// centre with dialog according to current window size. // centre with dialog according to current window size.
int newX = (int)((screenSize.width() - size.width())/2); int newX = (int)((screenSize.width() - size.width())/2);
int newY = (int)((screenSize.height() - size.height())/2); int newY = (int)((screenSize.height() - size.height())/2);
// Make sure that the window's title bar is accessible // Make sure that the window's title bar is accessible
if (newY <-0) if (newY <-0)
newY = 0; newY = 0;
proxy->setPos(newX, newY); proxy->setPos(newX, newY);
StelMainGraphicsView::getInstance().scene()->addItem(proxy);
proxy->setWindowFrameMargins(2,0,2,2); proxy->setWindowFrameMargins(2,0,2,2);
// (this also changes the bounding rectangle size) // (this also changes the bounding rectangle size)
// The caching is buggy on all plateforms with Qt 4.5.2 // The caching is buggy on all plateforms with Qt 4.5.2
proxy->setCacheMode(QGraphicsItem::ItemCoordinateCache); proxy->setCacheMode(QGraphicsItem::ItemCoordinateCache);
proxy->setZValue(100); proxy->setZValue(100);
StelMainGraphicsView::getInstance().scene()->setActiveWindow (proxy); StelMainView::getInstance().scene()->setActiveWindow(proxy);
proxy->setFocus(); proxy->setFocus();
} }
else else
{ {
dialog->hide(); dialog->hide();
emit visibleChanged(false); emit visibleChanged(false);
//proxy->clearFocus(); //proxy->clearFocus();
StelMainGraphicsView::getInstance().scene()->setActiveWindow (0); StelMainView::getInstance().focusSky();
} }
} }
 End of changes. 16 change blocks. 
17 lines changed or deleted 38 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/