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 "StelDialog_p.hpp"
#include "StelMainView.hpp" #include "StelMainView.hpp"
#include "StelGui.hpp" #include "StelGui.hpp"
#include "StelApp.hpp" #include "StelApp.hpp"
#include "StelActionMgr.hpp"
#include "StelPropertyMgr.hpp"
#include <QDebug> #include <QDebug>
#include <QAbstractButton>
#include <QComboBox>
#include <QDialog> #include <QDialog>
#include <QGraphicsProxyWidget> #include <QGraphicsProxyWidget>
#include <QMetaProperty>
#include <QStyleOptionGraphicsItem> #include <QStyleOptionGraphicsItem>
#include <QSettings> #include <QSettings>
#include <QSlider>
#include <QSpinBox>
#include <QDoubleSpinBox>
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
#include <QScroller> #include <QScroller>
#endif #endif
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);
skipping to change at line 98 skipping to change at line 107
setVisible(false); setVisible(false);
} }
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 == visible())
return;
if (v) if (v)
{ {
QSize screenSize = StelMainView::getInstance().size(); QSize screenSize = StelMainView::getInstance().size();
if (dialog) if (dialog)
{ {
dialog->show(); dialog->show();
StelMainView::getInstance().scene()->setActiveWindow (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();
return;
} }
else
{
QGraphicsWidget* parent = qobject_cast<QGraphicsWidg
et*>(this->parent());
dialog = new QDialog(NULL);
// dialog->setParent(parent);
StelGui* gui = dynamic_cast<StelGui*>(StelApp::getIn
stance().getGui());
Q_ASSERT(gui);
//dialog->setAttribute(Qt::WA_OpaquePaintEvent, true
);
connect(dialog, SIGNAL(rejected()), this, SLOT(close
()));
createDialogContent();
dialog->setStyleSheet(gui->getStelStyle().qtStyleShe
et);
// Ensure that tooltip get rendered in red in night
mode.
connect(&StelApp::getInstance(), SIGNAL(visionNightM
odeChanged(bool)), this, SLOT(updateNightModeProperty()));
updateNightModeProperty();
proxy = new CustomProxy(parent, Qt::Tool);
proxy->setWidget(dialog);
QSizeF size = proxy->size();
int newX, newY;
// Retrieve panel locations from config.ini, but shi
ft if required to a visible position.
// else centre dialog according to current window si
ze.
QSettings *conf=StelApp::getInstance().getSettings()
;
Q_ASSERT(conf);
QString confNamePt="DialogPositions/" + dialogName;
QString storedPosString=conf->value(confNamePt,
QString("%1,%2")
.arg((int)((scre
enSize.width() - size.width() )/2))
.arg((int)((scre
enSize.height() - size.height())/2)))
.toString();
QStringList posList=storedPosString.split(",");
if (posList.length()==2)
{
newX=posList.at(0).toInt();
newY=posList.at(1).toInt();
}
else // in case there is an invalid string?
{
newX=(int)((screenSize.width() - size.width
() )/2);
newY=(int)((screenSize.height() - size.heigh
t())/2);
}
QGraphicsWidget* parent = qobject_cast<QGraphicsWidget*>(thi if (newX>=screenSize.width())
s->parent()); newX= (screenSize.width() - dialog->size().
dialog = new QDialog(NULL); width());
// dialog->setParent(parent); if (newY>=screenSize.height())
StelGui* gui = dynamic_cast<StelGui*>(StelApp::getInstance() newY= (screenSize.height() - dialog->size().
.getGui()); height());
Q_ASSERT(gui);
//dialog->setAttribute(Qt::WA_OpaquePaintEvent, true); // Make sure that the window's title bar is accessib
connect(dialog, SIGNAL(rejected()), this, SLOT(close())); le
createDialogContent(); if (newY <-0)
dialog->setStyleSheet(gui->getStelStyle().qtStyleSheet); newY = 0;
proxy->setPos(newX, newY);
// Ensure that tooltip get rendered in red in night mode. proxy->setWindowFrameMargins(2,0,2,2);
connect(&StelApp::getInstance(), SIGNAL(visionNightModeChang // (this also changes the bounding rectangle size)
ed(bool)), this, SLOT(updateNightModeProperty()));
updateNightModeProperty();
proxy = new CustomProxy(parent, Qt::Tool);
proxy->setWidget(dialog);
QSizeF size = proxy->size();
// centre with dialog according to current window size.
int newX = (int)((screenSize.width() - size.width())/2);
int newY = (int)((screenSize.height() - size.height())/2);
// Make sure that the window's title bar is accessible
if (newY <-0)
newY = 0;
proxy->setPos(newX, newY);
proxy->setWindowFrameMargins(2,0,2,2);
// (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.
proxy->setCacheMode(QGraphicsItem::ItemCoordinateCache); 5.2
proxy->setCacheMode(QGraphicsItem::ItemCoordinateCac
he);
proxy->setZValue(100); proxy->setZValue(100);
StelMainView::getInstance().scene()->setActiveWindow(proxy); StelMainView::getInstance().scene()->setActiveWindow
(proxy);
}
proxy->setFocus(); proxy->setFocus();
} }
else else
{ {
dialog->hide(); dialog->hide();
emit visibleChanged(false);
//proxy->clearFocus(); //proxy->clearFocus();
StelMainView::getInstance().focusSky(); StelMainView::getInstance().focusSky();
} }
emit visibleChanged(v);
}
void StelDialog::connectCheckBox(QAbstractButton *checkBox, const QString &
actionName)
{
StelAction* action = StelApp::getInstance().getStelActionManager()->
findAction(actionName);
connectCheckBox(checkBox,action);
}
void StelDialog::connectCheckBox(QAbstractButton *checkBox, StelAction *act
ion)
{
Q_ASSERT(action);
checkBox->setChecked(action->isChecked());
connect(action, SIGNAL(toggled(bool)), checkBox, SLOT(setChecked(boo
l)));
connect(checkBox, SIGNAL(toggled(bool)), action, SLOT(setChecked(boo
l)));
}
void StelDialog::connectIntProperty(QSpinBox *spinBox, const QString &propN
ame)
{
StelProperty* prop = StelApp::getInstance().getStelPropertyManager()
->getProperty(propName);
Q_ASSERT_X(prop,"StelDialog", "StelProperty does not exist");
//use a proxy for the connection
new QSpinBoxStelPropertyConnectionHelper(prop,spinBox);
}
void StelDialog::connectIntProperty(QComboBox *comboBox, const QString &pro
pName)
{
StelProperty* prop = StelApp::getInstance().getStelPropertyManager()
->getProperty(propName);
Q_ASSERT_X(prop,"StelDialog", "StelProperty does not exist");
//use a proxy for the connection
new QComboBoxStelPropertyConnectionHelper(prop,comboBox);
}
void StelDialog::connectDoubleProperty(QDoubleSpinBox *spinBox, const QStri
ng &propName)
{
StelProperty* prop = StelApp::getInstance().getStelPropertyManager()
->getProperty(propName);
Q_ASSERT_X(prop,"StelDialog", "StelProperty does not exist");
//use a proxy for the connection
new QDoubleSpinBoxStelPropertyConnectionHelper(prop,spinBox);
}
void StelDialog::connectDoubleProperty(QSlider *slider, const QString &prop
Name,double minValue, double maxValue)
{
StelProperty* prop = StelApp::getInstance().getStelPropertyManager()
->getProperty(propName);
Q_ASSERT_X(prop,"StelDialog", "StelProperty does not exist");
//The connection is handled by a helper class. It is automatically d
estroyed when the slider is destroyed.
new QSliderStelPropertyConnectionHelper(prop,minValue,maxValue,slide
r);
}
void StelDialog::connectBoolProperty(QAbstractButton *checkBox, const QStri
ng &propName)
{
StelProperty* prop = StelApp::getInstance().getStelPropertyManager()
->getProperty(propName);
Q_ASSERT_X(prop,"StelDialog", "StelProperty does not exist");
new QAbstractButtonStelPropertyConnectionHelper(prop,checkBox);
} }
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
void StelDialog::installKineticScrolling(QList<QWidget *> addscroll) void StelDialog::installKineticScrolling(QList<QWidget *> addscroll)
{ {
return; // Temporary disable feature, bug in Qt: https://bugreports. qt-project.org/browse/QTBUG-41299 return; // Temporary disable feature, bug in Qt: https://bugreports. qt-project.org/browse/QTBUG-41299
if (StelApp::getInstance().getSettings()->value("gui/flag_enable_kin etic_scrolling", true).toBool() == false) if (StelApp::getInstance().getSettings()->value("gui/flag_enable_kin etic_scrolling", true).toBool() == false)
return; return;
skipping to change at line 184 skipping to change at line 278
QScroller::grabGesture(w, QScroller::LeftMouseButtonGesture) ; QScroller::grabGesture(w, QScroller::LeftMouseButtonGesture) ;
QScroller::scroller(w); QScroller::scroller(w);
} }
} }
#endif #endif
void StelDialog::updateNightModeProperty() void StelDialog::updateNightModeProperty()
{ {
dialog->setProperty("nightMode", StelApp::getInstance().getVisionMod eNight()); dialog->setProperty("nightMode", StelApp::getInstance().getVisionMod eNight());
} }
void StelDialog::handleMovedTo(QPoint newPos)
{
QSettings *conf=StelApp::getInstance().getSettings();
Q_ASSERT(conf);
conf->setValue("DialogPositions/" + dialogName, QString("%1,%2").arg
(newPos.x()).arg(newPos.y()));
}
//// --- Implementation of StelDialog_p.hpp classes follow ---
QAbstractButtonStelPropertyConnectionHelper::QAbstractButtonStelPropertyCon
nectionHelper(StelProperty *prop, QAbstractButton *button)
:StelPropertyProxy(prop,button), button(button)
{
QVariant val = prop->getValue();
bool ok = val.canConvert<bool>();
Q_ASSERT_X(ok,"QAbstractButtonStelPropertyConnectionHelper","Can not
convert to bool datatype");
Q_UNUSED(ok);
onPropertyChanged(val);
//in this direction, we can directly connect because Qt supports QVa
riant slots with the new syntax
connect(button, &QAbstractButton::toggled, prop, &StelProperty::setV
alue);
}
void QAbstractButtonStelPropertyConnectionHelper::onPropertyChanged(const Q
Variant &value)
{
//block signals to prevent sending the valueChanged signal, changing
the property again
bool b = button->blockSignals(true);
button->setChecked(value.toBool());
button->blockSignals(b);
}
QComboBoxStelPropertyConnectionHelper::QComboBoxStelPropertyConnectionHelpe
r(StelProperty *prop, QComboBox *combo)
:StelPropertyProxy(prop,combo), combo(combo)
{
QVariant val = prop->getValue();
bool ok = val.canConvert<int>();
Q_ASSERT_X(ok,"QComboBoxStelPropertyConnectionHelper","Can not conve
rt to int datatype");
Q_UNUSED(ok);
onPropertyChanged(val);
//in this direction, we can directly connect because Qt supports QVa
riant slots with the new syntax
connect(combo, static_cast<void (QComboBox::*)(int)>(&QComboBox::act
ivated),prop,&StelProperty::setValue);
}
void QComboBoxStelPropertyConnectionHelper::onPropertyChanged(const QVarian
t &value)
{
//block signals to prevent sending the valueChanged signal, changing
the property again
bool b = combo->blockSignals(true);
combo->setCurrentIndex(value.toInt());
combo->blockSignals(b);
}
QSpinBoxStelPropertyConnectionHelper::QSpinBoxStelPropertyConnectionHelper(
StelProperty *prop, QSpinBox *spin)
:StelPropertyProxy(prop,spin), spin(spin)
{
QVariant val = prop->getValue();
bool ok = val.canConvert<int>();
Q_ASSERT_X(ok,"QSpinBoxStelPropertyConnectionHelper","Can not conver
t to int datatype");
Q_UNUSED(ok);
onPropertyChanged(val);
//in this direction, we can directly connect because Qt supports QVa
riant slots with the new syntax
connect(spin, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueC
hanged),prop,&StelProperty::setValue);
}
void QSpinBoxStelPropertyConnectionHelper::onPropertyChanged(const QVariant
&value)
{
//block signals to prevent sending the valueChanged signal, changing
the property again
bool b = spin->blockSignals(true);
spin->setValue(value.toInt());
spin->blockSignals(b);
}
QDoubleSpinBoxStelPropertyConnectionHelper::QDoubleSpinBoxStelPropertyConne
ctionHelper(StelProperty *prop, QDoubleSpinBox *spin)
:StelPropertyProxy(prop,spin), spin(spin)
{
QVariant val = prop->getValue();
bool ok = val.canConvert<double>();
Q_ASSERT_X(ok,"QDoubleSpinBoxStelPropertyConnectionHelper","Can not
convert to double datatype");
Q_UNUSED(ok);
onPropertyChanged(val);
//in this direction, we can directly connect because Qt supports QVa
riant slots with the new syntax
connect(spin, static_cast<void (QDoubleSpinBox::*)(double)>(&QDouble
SpinBox::valueChanged),prop,&StelProperty::setValue);
}
void QDoubleSpinBoxStelPropertyConnectionHelper::onPropertyChanged(const QV
ariant &value)
{
//block signals to prevent sending the valueChanged signal, changing
the property again
bool b = spin->blockSignals(true);
spin->setValue(value.toDouble());
spin->blockSignals(b);
}
QSliderStelPropertyConnectionHelper::QSliderStelPropertyConnectionHelper(St
elProperty *prop, double minValue, double maxValue, QSlider *slider)
: StelPropertyProxy(prop,slider),slider(slider),minValue(minValue),m
axValue(maxValue)
{
QVariant val = prop->getValue();
bool ok = val.canConvert<double>();
Q_ASSERT_X(ok,"QSliderStelPropertyConnectionHelper","Can not convert
to double datatype");
Q_UNUSED(ok);
dRange = maxValue - minValue;
onPropertyChanged(val);
connect(slider,SIGNAL(valueChanged(int)),this,SLOT(sliderIntValueCha
nged(int)));
}
void QSliderStelPropertyConnectionHelper::sliderIntValueChanged(int val)
{
double dVal = ((val - slider->minimum()) / (double)(slider->maximum(
) - slider->minimum())) * dRange + minValue;
prop->setValue(dVal);
}
void QSliderStelPropertyConnectionHelper::onPropertyChanged(const QVariant&
val)
{
double dVal = val.toDouble();
int iRange = slider->maximum() - slider->minimum();
int iVal = qRound(((dVal - minValue)/dRange) * iRange + slider->mini
mum());
bool b = slider->blockSignals(true);
slider->setValue(iVal);
slider->blockSignals(b);
}
 End of changes. 14 change blocks. 
38 lines changed or deleted 166 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/