Stellarium  0.16.1
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=Q_NULLPTR);
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);
104  virtual void handleDialogSizeChanged(QSizeF size);
105  QString getDialogName(){return dialogName;}
106 signals:
107  void visibleChanged(bool);
108 
109 protected:
111  virtual void createDialogContent()=0;
112 
114  static void connectCheckBox(QAbstractButton* checkBox,const QString& actionName);
116  static void connectCheckBox(QAbstractButton *checkBox, StelAction* action);
117 
122  static void connectIntProperty(QSpinBox* spinBox, const QString& propName);
128  static void connectIntProperty(QComboBox* comboBox, const QString& propName);
136  static void connectIntProperty(QSlider* slider, const QString& propName, int minValue, int maxValue);
140  static void connectDoubleProperty(QDoubleSpinBox* spinBox, const QString& propName);
148  static void connectDoubleProperty(QSlider* slider, const QString& propName, double minValue, double maxValue);
152  static void connectBoolProperty(QAbstractButton* checkBox, const QString& propName);
153 
155  QWidget* dialog;
156  class CustomProxy* proxy;
158  QString dialogName;
159 
160 #ifdef Q_OS_WIN
161  void installKineticScrolling(QList<QWidget *> addscroll);
164 #endif
165 
166 private slots:
167  void updateNightModeProperty();
168 };
169 
170 class CustomProxy : public QGraphicsProxyWidget
171 { private:
172  Q_OBJECT
173  public:
174  CustomProxy(QGraphicsItem *parent = Q_NULLPTR, Qt::WindowFlags wFlags = 0) : QGraphicsProxyWidget(parent, wFlags)
175  {
176  setFocusPolicy(Qt::StrongFocus);
177  }
179  void paintWindowFrame(QPainter*, const QStyleOptionGraphicsItem*, QWidget*)
180  {
181 /* QStyleOptionTitleBar bar;
182  initStyleOption(&bar);
183  bar.subControls = QStyle::SC_TitleBarCloseButton;
184  qWarning() << style()->subControlRect(QStyle::CC_TitleBar, &bar, QStyle::SC_TitleBarCloseButton);
185  QGraphicsProxyWidget::paintWindowFrame(painter, option, widget);*/
186  }
187  signals: void sizeChanged(QSizeF);
188  protected:
189 
190  virtual bool event(QEvent* event)
191  {
192  if (StelApp::getInstance().getSettings()->value("gui/flag_use_window_transparency", true).toBool())
193  {
194  switch (event->type())
195  {
196  case QEvent::WindowDeactivate:
197  widget()->setWindowOpacity(0.4);
198  break;
199  case QEvent::WindowActivate:
200  case QEvent::GrabMouse:
201  widget()->setWindowOpacity(0.9);
202  break;
203  default:
204  break;
205  }
206  }
207  return QGraphicsProxyWidget::event(event);
208  }
209  virtual void resizeEvent(QGraphicsSceneResizeEvent *event)
210  {
211  if (event->newSize() != event->oldSize())
212  {
213  emit sizeChanged(event->newSize());
214  }
215  QGraphicsProxyWidget::resizeEvent(event);
216  }
217 };
218 #endif // _STELDIALOG_HPP_
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:179
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:158
virtual void handleDialogSizeChanged(QSizeF size)
Stores dialog sizes into config.ini; should be connected from the proxy.
static StelApp & getInstance()
Get the StelApp singleton instance.
Definition: StelApp.hpp:105
QWidget * dialog
The main dialog.
Definition: StelDialog.hpp:155
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.