Stellarium 0.15.2
StelDialog.hpp
1 /*
2  * Stellarium
3  * Copyright (C) 2008 Fabien Chereau
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
18 */
19 
20 #ifndef _STELDIALOG_HPP_
21 #define _STELDIALOG_HPP_
22 
23 #include <QObject>
24 #include <QGraphicsProxyWidget>
25 #include <QGraphicsSceneResizeEvent>
26 #include <QSettings>
27 #include <QWidget>
28 #include "StelApp.hpp"
29 
30 class QAbstractButton;
31 class QComboBox;
32 class QSpinBox;
33 class QDoubleSpinBox;
34 class QSlider;
35 class StelAction;
36 
72 class StelDialog : public QObject
73 {
74  Q_OBJECT
75  Q_PROPERTY(bool visible READ visible WRITE setVisible NOTIFY visibleChanged)
76 public:
77  StelDialog(QString dialogName="Default", QObject* parent=NULL);
78  virtual ~StelDialog();
79 
81  bool visible() const;
82 
83 public slots:
94  virtual void retranslate() = 0;
96  void setVisible(bool);
98  void close();
100  void handleMovedTo(QPoint newPos);
102  void handleDialogSizeChanged(QSizeF size);
103  QString getDialogName(){return dialogName;}
104 signals:
105  void visibleChanged(bool);
106 
107 protected:
109  virtual void createDialogContent()=0;
110 
112  static void connectCheckBox(QAbstractButton* checkBox,const QString& actionName);
114  static void connectCheckBox(QAbstractButton *checkBox, StelAction* action);
115 
120  static void connectIntProperty(QSpinBox* spinBox, const QString& propName);
126  static void connectIntProperty(QComboBox* comboBox, const QString& propName);
134  static void connectIntProperty(QSlider* slider, const QString& propName, int minValue, int maxValue);
138  static void connectDoubleProperty(QDoubleSpinBox* spinBox, const QString& propName);
146  static void connectDoubleProperty(QSlider* slider, const QString& propName, double minValue, double maxValue);
150  static void connectBoolProperty(QAbstractButton* checkBox, const QString& propName);
151 
153  QWidget* dialog;
154  class CustomProxy* proxy;
156  QString dialogName;
157 
158 #ifdef Q_OS_WIN
159  void installKineticScrolling(QList<QWidget *> addscroll);
161 #endif
162 
163 private slots:
164  void updateNightModeProperty();
165 };
166 
167 class CustomProxy : public QGraphicsProxyWidget
168 { private:
169  Q_OBJECT
170  public:
171  CustomProxy(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0) : QGraphicsProxyWidget(parent, wFlags)
172  {
173  setFocusPolicy(Qt::StrongFocus);
174  }
176  void paintWindowFrame(QPainter*, const QStyleOptionGraphicsItem*, QWidget*)
177  {
178 /* QStyleOptionTitleBar bar;
179  initStyleOption(&bar);
180  bar.subControls = QStyle::SC_TitleBarCloseButton;
181  qWarning() << style()->subControlRect(QStyle::CC_TitleBar, &bar, QStyle::SC_TitleBarCloseButton);
182  QGraphicsProxyWidget::paintWindowFrame(painter, option, widget);*/
183  }
184  signals: void sizeChanged(QSizeF);
185  protected:
186 
187  virtual bool event(QEvent* event)
188  {
189  if (StelApp::getInstance().getSettings()->value("gui/flag_use_window_transparency", true).toBool())
190  {
191  switch (event->type())
192  {
193  case QEvent::WindowDeactivate:
194  widget()->setWindowOpacity(0.4);
195  break;
196  case QEvent::WindowActivate:
197  case QEvent::GrabMouse:
198  widget()->setWindowOpacity(0.9);
199  break;
200  default:
201  break;
202  }
203  }
204  return QGraphicsProxyWidget::event(event);
205  }
206  virtual void resizeEvent(QGraphicsSceneResizeEvent *event)
207  {
208  if (event->newSize() != event->oldSize())
209  {
210  emit sizeChanged(event->newSize());
211  }
212  QGraphicsProxyWidget::resizeEvent(event);
213  }
214 };
215 #endif // _STELDIALOG_HPP_
void handleDialogSizeChanged(QSizeF size)
Stores dialog sizes into config.ini; should be connected from the proxy.
void handleMovedTo(QPoint newPos)
Adds dialog location to config.ini; should be connected in createDialogContent()
void close()
Closes the window (the window widget is not deleted, just not visible).
static void connectBoolProperty(QAbstractButton *checkBox, const QString &propName)
Helper function to connect a checkbox to a bool StelProperty.
void paintWindowFrame(QPainter *, const QStyleOptionGraphicsItem *, QWidget *)
Reimplement this method to add windows decorations. Currently there are invisible 2 px decorations...
Definition: StelDialog.hpp:176
static void connectIntProperty(QSpinBox *spinBox, const QString &propName)
Helper function to connect a QSpinBox to an integer StelProperty.
virtual void createDialogContent()=0
Initialize the dialog widgets and connect the signals/slots.
Base class for all the GUI windows in Stellarium.
Definition: StelDialog.hpp:72
static void connectCheckBox(QAbstractButton *checkBox, const QString &actionName)
Helper function to connect a checkbox to the StelAction with the specified name.
void setVisible(bool)
On the first call with "true" populates the window contents.
static void connectDoubleProperty(QDoubleSpinBox *spinBox, const QString &propName)
Helper function to connect a QDoubleSpinBox to an double or float StelProperty.
Wrapper around an argumentless QObject slot or a bool Q_PROPERTY with WRITE method, allowing the slot to be called/property to be toggled using this action object.
QString dialogName
The name should be set in derived classes&#39; constructors and can be used to store and retrieve the pan...
Definition: StelDialog.hpp:156
static StelApp & getInstance()
Get the StelApp singleton instance.
Definition: StelApp.hpp:100
QWidget * dialog
The main dialog.
Definition: StelDialog.hpp:153
virtual void retranslate()=0
Retranslate the content of the dialog.
bool visible() const
Returns true if the dialog contents have been constructed and are currently shown.