summaryrefslogtreecommitdiffstats
path: root/src/gui/widgets/qdialogbuttonbox.cpp
diff options
context:
space:
mode:
authorSami Merilä <sami.merila@nokia.com>2009-09-18 16:06:46 (GMT)
committerJason Barron <jbarron@trolltech.com>2009-09-21 08:06:19 (GMT)
commit58b92a951899f74b63048a36c451d3355c0c5a7f (patch)
treefec4e8be5ca11570979e3f0a8de3f6a7407c661f /src/gui/widgets/qdialogbuttonbox.cpp
parent75c4d11b8260ab74bcbf403c32333b81e5ef30e3 (diff)
downloadQt-58b92a951899f74b63048a36c451d3355c0c5a7f.zip
Qt-58b92a951899f74b63048a36c451d3355c0c5a7f.tar.gz
Qt-58b92a951899f74b63048a36c451d3355c0c5a7f.tar.bz2
S60 native looking dialog support.
Related to QTSSIXTY-63 "Make Qt dialogs look native" S60 dialog support: * Positioning according S60 rules: - in portrait dialogs at the bottom of the screen, - in landscape positioned in the center of the screen [unless device supports bottom softkeys], so that softkeys are not covered by the dialog * If dialog shows extension, then dialog is re-positioned * Dialog size: - in portrait screen wide dialog, height can change - in landscape width is the same size as width in portrait (some dialogs are maximized) * No push buttons or DialogButtonBoxes in internal qt dialogs (QWizard, QInputDialog, QFileDialog, QFontDialog, QColorDialog, QProgressDialog, QErrorMessage, QMessageBox), instead signals are remapped to softkeys. * Globally, dialogbuttonboxes are converted automatically to softkeys. OPEN: * Needs to be re-factored slightly after softkey API refactoring is finished. BUGS: QWizard layout switch is wonky - dialog is not re-sized correctly. QFontDialog will not fit into device screen (too much widgets in it). Some effort needed to be make it smaller. Cannot set one softkey at the time softkeys => Options menu and right softkey cannot be set separately [SoftKey re-factoring will help] Dialogs cannot get touch events to softkeys [SoftKey re-factoring will help] Reviewed-by: Alessandro Portale Reviewed-by: Jason Barron Reviewed-by: mread Reviewed-by: Shane Kearns
Diffstat (limited to 'src/gui/widgets/qdialogbuttonbox.cpp')
-rw-r--r--src/gui/widgets/qdialogbuttonbox.cpp142
1 files changed, 142 insertions, 0 deletions
diff --git a/src/gui/widgets/qdialogbuttonbox.cpp b/src/gui/widgets/qdialogbuttonbox.cpp
index ef0b7b2..5eac611 100644
--- a/src/gui/widgets/qdialogbuttonbox.cpp
+++ b/src/gui/widgets/qdialogbuttonbox.cpp
@@ -49,6 +49,14 @@
#include "qdialogbuttonbox.h"
+
+#ifdef Q_WS_S60
+#include <QtGui/qaction.h>
+#include <QtGui/qmenubar.h>
+#include <QtGui/qmenu.h>
+#endif
+
+
QT_BEGIN_NAMESPACE
/*!
@@ -263,6 +271,9 @@ public:
QList<QAbstractButton *> buttonLists[QDialogButtonBox::NRoles];
QHash<QPushButton *, QDialogButtonBox::StandardButton> standardButtonHash;
+#ifdef Q_WS_S60
+ QList<QAction *> softkeyActions;
+#endif
Qt::Orientation orientation;
QDialogButtonBox::ButtonLayout layoutPolicy;
@@ -282,6 +293,10 @@ public:
void addButtonsToLayout(const QList<QAbstractButton *> &buttonList, bool reverse);
void retranslateStrings();
const char *standardButtonText(QDialogButtonBox::StandardButton sbutton) const;
+#ifdef Q_WS_S60
+ void addSoftKeyAction(QAbstractButton *button, QDialogButtonBox::ButtonRole role);
+ void setSoftKeys();
+#endif
};
QDialogButtonBoxPrivate::QDialogButtonBoxPrivate(Qt::Orientation orient)
@@ -457,6 +472,18 @@ void QDialogButtonBoxPrivate::layoutButtons()
if (center)
buttonLayout->addStretch();
+
+#ifdef Q_WS_S60
+ QWidget *dialog = 0;
+ QWidget *p = q;
+ while (p && !p->isWindow()) {
+ p = p->parentWidget();
+ if (dialog = qobject_cast<QDialog *>(p))
+ break;
+ }
+ if (dialog)
+ q->hide();
+#endif
}
QPushButton *QDialogButtonBoxPrivate::createButton(QDialogButtonBox::StandardButton sbutton,
@@ -540,6 +567,115 @@ void QDialogButtonBoxPrivate::addButton(QAbstractButton *button, QDialogButtonBo
layoutButtons();
}
+/*! \internal */
+#ifdef Q_WS_S60
+void QDialogButtonBoxPrivate::addSoftKeyAction(QAbstractButton *button, QDialogButtonBox::ButtonRole role)
+{
+ Q_Q(QDialogButtonBox);
+
+ QAction::SoftKeyRole softkeyRole;
+ QAction *buttonAction = new QAction(button->text(), q);
+
+ switch (role) {
+ case ApplyRole:
+ case AcceptRole:
+ softkeyRole = QAction::OkSoftKey;
+ break;
+ case RejectRole:
+ softkeyRole = QAction::CancelSoftKey;
+ break;
+ case DestructiveRole:
+ softkeyRole = QAction::ExitSoftKey;
+ break;
+ case ActionRole:
+ case HelpRole:
+ softkeyRole = QAction::ViewSoftKey; //todo: uhh
+ break;
+ case YesRole:
+ softkeyRole = QAction::SelectSoftKey;
+ break;
+ case NoRole:
+ softkeyRole = QAction::DeselectSoftKey;
+ break;
+ case ResetRole:
+ softkeyRole = QAction::BackSoftKey;
+ break;
+ default:
+ break;
+ }
+ QObject::connect(buttonAction, SIGNAL(triggered()), button, SIGNAL(clicked()));
+ buttonAction->setSoftKeyRole(softkeyRole);
+ softkeyActions.append(buttonAction);
+}
+
+/*! \internal */
+void QDialogButtonBoxPrivate::setSoftKeys()
+{
+ Q_Q(QDialogButtonBox);
+
+ QDialog *dialog = 0;
+ QWidget *p = q;
+ while (p && !p->isWindow()) {
+ p = p->parentWidget();
+ if ((dialog = qobject_cast<QDialog *>(p)))
+ break;
+ }
+ if (dialog) {
+ softkeyActions.clear();
+ const int buttonCount = q->buttons().count();
+ for (int i=0; i< buttonCount; i++){
+ QAbstractButton *button = q->buttons().at(i);
+ QDialogButtonBox::ButtonRole role = q->buttonRole(button);
+ addSoftKeyAction(button, role);
+ }
+ //Need to re-arrange softkeys, if there are too many actions.
+ if (softkeyActions.count() > 2){
+ //FIXME- wait for Softkey API refactoring
+ /*
+ QAction *actionSoftKeyOption = new QAction(tr("Options"), this);
+ actionSoftKeyOption->setSoftKeyRole(QAction::OptionsSoftKey);
+ setSoftKey(actionSoftKeyOption);
+
+ QMenuBar *menuBarOptions = new QMenuBar(q->parentWidget());
+ menubarOptions->addActions(softkeyActions);
+ buttonLayout->setMenuBar(menuBar);
+ */
+ //Set right softkey
+ softkeyActions.clear();
+ QAction::SoftKeyRole softKeyAction;
+ QAbstractButton *lskButton;
+ QList<QAbstractButton *> &searchList = buttonLists[DestructiveRole];
+ if (searchList.count() > 0){
+ lskButton = searchList.at(0);
+ softKeyAction = QAction::ExitSoftKey;
+ } else {
+ searchList = buttonLists[RejectRole];
+ if (searchList.count() > 0){
+ lskButton = searchList.at(0);
+ softKeyAction = QAction::CancelSoftKey;
+ } else {
+ searchList = buttonLists[NoRole];
+ if (searchList.count() > 0) {
+ lskButton = searchList.at(0);
+ softKeyAction = QAction::DeselectSoftKey;
+ } else {
+ //no good candidates, rely on SoftKey API
+ }
+ }
+ }
+ QAction *leftSoftKeyAction = new QAction(lskButton->text(), dialog);
+ leftSoftKeyAction->setSoftKeyRole(softKeyAction);
+ QObject::connect(leftSoftKeyAction, SIGNAL(triggered()), lskButton, SIGNAL(clicked()));
+ softkeyActions.append(leftSoftKeyAction);
+ dialog->setSoftKeys(softkeyActions);
+ } else {
+ dialog->setSoftKeys(softkeyActions);
+ }
+ }
+}
+
+#endif
+
void QDialogButtonBoxPrivate::createStandardButtons(QDialogButtonBox::StandardButtons buttons)
{
uint i = QDialogButtonBox::FirstButton;
@@ -1128,6 +1264,12 @@ bool QDialogButtonBox::event(QEvent *event)
}else if (event->type() == QEvent::LanguageChange) {
d->retranslateStrings();
}
+#ifdef Q_WS_S60
+ // Set the softkeys in polish, to avoid doing them several times, since each call causes flicker in the softkeys.
+ else if (event->type() == QEvent::Polish) {
+ d->setSoftKeys();
+ }
+#endif
return QWidget::event(event);
}