diff options
| author | Tobias Markmann <tm@ayena.de> | 2015-06-03 06:19:49 (GMT) |
|---|---|---|
| committer | Kevin Smith <kevin.smith@isode.com> | 2015-06-05 19:52:20 (GMT) |
| commit | 3741c9ad5c0cc6f92e4ed913d67b3b530882334e (patch) | |
| tree | baa449dcf475ceb291444bb80e78196d94ccc1e4 | |
| parent | dba9757d5805ab308b56c9e623a076426b2dd4c2 (diff) | |
| download | swift-3741c9ad5c0cc6f92e4ed913d67b3b530882334e.zip swift-3741c9ad5c0cc6f92e4ed913d67b3b530882334e.tar.bz2 | |
UI improvements to the ad-hoc command window
Use QDialogButtonBox instead of custom button layout code. This way
the button are correctly layouted depending on platform guidelines.
Show a 'Ok' button if no other button is shown which closes the window.
Test-Information:
Tested on OS X 10.9.5 with Qt 5.4.2.
Change-Id: I37581982766d013f4d3d636880fd5ada59ee0c40
| -rw-r--r-- | Swift/QtUI/QtAdHocCommandWindow.cpp | 45 | ||||
| -rw-r--r-- | Swift/QtUI/QtAdHocCommandWindow.h | 15 |
2 files changed, 39 insertions, 21 deletions
diff --git a/Swift/QtUI/QtAdHocCommandWindow.cpp b/Swift/QtUI/QtAdHocCommandWindow.cpp index a6bce65..ef397f4 100644 --- a/Swift/QtUI/QtAdHocCommandWindow.cpp +++ b/Swift/QtUI/QtAdHocCommandWindow.cpp | |||
| @@ -1,17 +1,21 @@ | |||
| 1 | /* | 1 | /* |
| 2 | * Copyright (c) 2010-2014 Isode Limited. | 2 | * Copyright (c) 2010-2015 Isode Limited. |
| 3 | * All rights reserved. | 3 | * All rights reserved. |
| 4 | * See the COPYING file for more information. | 4 | * See the COPYING file for more information. |
| 5 | */ | 5 | */ |
| 6 | 6 | ||
| 7 | #include <Swift/QtUI/QtAdHocCommandWindow.h> | ||
| 8 | |||
| 7 | #include <boost/bind.hpp> | 9 | #include <boost/bind.hpp> |
| 10 | |||
| 8 | #include <QBoxLayout> | 11 | #include <QBoxLayout> |
| 9 | #include <Swift/QtUI/QtAdHocCommandWindow.h> | 12 | |
| 10 | #include <Swift/QtUI/QtFormWidget.h> | ||
| 11 | #include <Swift/QtUI/QtSwiftUtil.h> | ||
| 12 | #include <Swiften/Base/format.h> | 13 | #include <Swiften/Base/format.h> |
| 13 | #include <Swiften/Elements/Command.h> | 14 | #include <Swiften/Elements/Command.h> |
| 14 | 15 | ||
| 16 | #include <Swift/QtUI/QtFormWidget.h> | ||
| 17 | #include <Swift/QtUI/QtSwiftUtil.h> | ||
| 18 | |||
| 15 | const int FormLayoutIndex = 1; | 19 | const int FormLayoutIndex = 1; |
| 16 | 20 | ||
| 17 | namespace Swift { | 21 | namespace Swift { |
| @@ -36,22 +40,25 @@ QtAdHocCommandWindow::QtAdHocCommandWindow(boost::shared_ptr<OutgoingAdHocComman | |||
| 36 | errorLabel_->setFrameStyle(QFrame::Box|QFrame::Sunken); | 40 | errorLabel_->setFrameStyle(QFrame::Box|QFrame::Sunken); |
| 37 | layout_->addWidget(errorLabel_); | 41 | layout_->addWidget(errorLabel_); |
| 38 | 42 | ||
| 39 | QWidget* buttonsWidget = new QWidget(this); | 43 | dialogButtons_ = new QDialogButtonBox(this); |
| 40 | layout_->addWidget(buttonsWidget); | 44 | layout_->addWidget(dialogButtons_); |
| 41 | 45 | ||
| 42 | QBoxLayout* buttonsLayout = new QBoxLayout(QBoxLayout::LeftToRight, buttonsWidget); | 46 | dialogButtons_->setStandardButtons(QDialogButtonBox::Cancel | QDialogButtonBox::Ok); |
| 43 | cancelButton_ = new QPushButton(tr("Cancel"), buttonsWidget); | 47 | okButton_ = dialogButtons_->button(QDialogButtonBox::Ok); |
| 44 | buttonsLayout->addWidget(cancelButton_); | 48 | connect(okButton_, SIGNAL(clicked()), this, SLOT(close())); |
| 49 | cancelButton_ = dialogButtons_->button(QDialogButtonBox::Cancel); | ||
| 45 | connect(cancelButton_, SIGNAL(clicked()), this, SLOT(handleCancelClicked())); | 50 | connect(cancelButton_, SIGNAL(clicked()), this, SLOT(handleCancelClicked())); |
| 46 | backButton_ = new QPushButton(tr("Back"), buttonsWidget); | 51 | // Buttons appear next to the Ok button, right of Cancel with YesRole |
| 47 | buttonsLayout->addWidget(backButton_); | 52 | completeButton_ = dialogButtons_->addButton(tr("Complete"), QDialogButtonBox::YesRole); |
| 48 | connect(backButton_, SIGNAL(clicked()), this, SLOT(handlePrevClicked())); | ||
| 49 | nextButton_ = new QPushButton(tr("Next"), buttonsWidget); | ||
| 50 | buttonsLayout->addWidget(nextButton_); | ||
| 51 | connect(nextButton_, SIGNAL(clicked()), this, SLOT(handleNextClicked())); | ||
| 52 | completeButton_ = new QPushButton(tr("Complete"), buttonsWidget); | ||
| 53 | buttonsLayout->addWidget(completeButton_); | ||
| 54 | connect(completeButton_, SIGNAL(clicked()), this, SLOT(handleCompleteClicked())); | 53 | connect(completeButton_, SIGNAL(clicked()), this, SLOT(handleCompleteClicked())); |
| 54 | nextButton_ = dialogButtons_->addButton(tr("Next"), QDialogButtonBox::YesRole); | ||
| 55 | connect(nextButton_, SIGNAL(clicked()), this, SLOT(handleNextClicked())); | ||
| 56 | backButton_ = dialogButtons_->addButton(tr("Back"), QDialogButtonBox::YesRole); | ||
| 57 | connect(backButton_, SIGNAL(clicked()), this, SLOT(handlePrevClicked())); | ||
| 58 | |||
| 59 | okButton_->setEnabled(false); | ||
| 60 | okButton_->hide(); | ||
| 61 | |||
| 55 | nextButton_->setEnabled(false); | 62 | nextButton_->setEnabled(false); |
| 56 | backButton_->setEnabled(false); | 63 | backButton_->setEnabled(false); |
| 57 | completeButton_->setEnabled(false); | 64 | completeButton_->setEnabled(false); |
| @@ -143,9 +150,13 @@ void QtAdHocCommandWindow::setNoForm(bool andHide) { | |||
| 143 | typedef std::pair<Command::Action, QPushButton*> ActionButton; | 150 | typedef std::pair<Command::Action, QPushButton*> ActionButton; |
| 144 | 151 | ||
| 145 | void QtAdHocCommandWindow::setAvailableActions(Command::ref /*commandResult*/) { | 152 | void QtAdHocCommandWindow::setAvailableActions(Command::ref /*commandResult*/) { |
| 153 | okButton_->show(); | ||
| 154 | okButton_->setEnabled(true); | ||
| 146 | foreach (ActionButton pair, actions_) { | 155 | foreach (ActionButton pair, actions_) { |
| 147 | OutgoingAdHocCommandSession::ActionState state = command_->getActionState(pair.first); | 156 | OutgoingAdHocCommandSession::ActionState state = command_->getActionState(pair.first); |
| 148 | if (state & OutgoingAdHocCommandSession::Present) { | 157 | if (state & OutgoingAdHocCommandSession::Present) { |
| 158 | okButton_->hide(); | ||
| 159 | okButton_->setEnabled(false); | ||
| 149 | pair.second->show(); | 160 | pair.second->show(); |
| 150 | } | 161 | } |
| 151 | else { | 162 | else { |
diff --git a/Swift/QtUI/QtAdHocCommandWindow.h b/Swift/QtUI/QtAdHocCommandWindow.h index 231a51c..c8d493c 100644 --- a/Swift/QtUI/QtAdHocCommandWindow.h +++ b/Swift/QtUI/QtAdHocCommandWindow.h | |||
| @@ -1,18 +1,20 @@ | |||
| 1 | /* | 1 | /* |
| 2 | * Copyright (c) 2010-2012 Isode Limited. | 2 | * Copyright (c) 2010-2015 Isode Limited. |
| 3 | * All rights reserved. | 3 | * All rights reserved. |
| 4 | * See the COPYING file for more information. | 4 | * See the COPYING file for more information. |
| 5 | */ | 5 | */ |
| 6 | 6 | ||
| 7 | #pragma once | 7 | #pragma once |
| 8 | 8 | ||
| 9 | #include <QWidget> | 9 | #include <QDialogButtonBox> |
| 10 | #include <QPushButton> | ||
| 11 | #include <QLabel> | 10 | #include <QLabel> |
| 11 | #include <QPushButton> | ||
| 12 | #include <QWidget> | ||
| 12 | 13 | ||
| 13 | #include <Swift/Controllers/UIInterfaces/AdHocCommandWindow.h> | ||
| 14 | #include <Swiften/AdHoc/OutgoingAdHocCommandSession.h> | 14 | #include <Swiften/AdHoc/OutgoingAdHocCommandSession.h> |
| 15 | 15 | ||
| 16 | #include <Swift/Controllers/UIInterfaces/AdHocCommandWindow.h> | ||
| 17 | |||
| 16 | class QBoxLayout; | 18 | class QBoxLayout; |
| 17 | 19 | ||
| 18 | namespace Swift { | 20 | namespace Swift { |
| @@ -23,6 +25,7 @@ namespace Swift { | |||
| 23 | QtAdHocCommandWindow(boost::shared_ptr<OutgoingAdHocCommandSession> command); | 25 | QtAdHocCommandWindow(boost::shared_ptr<OutgoingAdHocCommandSession> command); |
| 24 | virtual ~QtAdHocCommandWindow(); | 26 | virtual ~QtAdHocCommandWindow(); |
| 25 | virtual void setOnline(bool online); | 27 | virtual void setOnline(bool online); |
| 28 | |||
| 26 | private: | 29 | private: |
| 27 | void closeEvent(QCloseEvent* event); | 30 | void closeEvent(QCloseEvent* event); |
| 28 | void handleNextStageReceived(Command::ref command); | 31 | void handleNextStageReceived(Command::ref command); |
| @@ -30,11 +33,13 @@ namespace Swift { | |||
| 30 | void setForm(Form::ref); | 33 | void setForm(Form::ref); |
| 31 | void setNoForm(bool andHide); | 34 | void setNoForm(bool andHide); |
| 32 | void setAvailableActions(Command::ref commandResult); | 35 | void setAvailableActions(Command::ref commandResult); |
| 36 | |||
| 33 | private slots: | 37 | private slots: |
| 34 | void handleCancelClicked(); | 38 | void handleCancelClicked(); |
| 35 | void handlePrevClicked(); | 39 | void handlePrevClicked(); |
| 36 | void handleNextClicked(); | 40 | void handleNextClicked(); |
| 37 | void handleCompleteClicked(); | 41 | void handleCompleteClicked(); |
| 42 | |||
| 38 | private: | 43 | private: |
| 39 | boost::shared_ptr<OutgoingAdHocCommandSession> command_; | 44 | boost::shared_ptr<OutgoingAdHocCommandSession> command_; |
| 40 | QtFormWidget* formWidget_; | 45 | QtFormWidget* formWidget_; |
| @@ -45,7 +50,9 @@ namespace Swift { | |||
| 45 | QPushButton* nextButton_; | 50 | QPushButton* nextButton_; |
| 46 | QPushButton* completeButton_; | 51 | QPushButton* completeButton_; |
| 47 | QPushButton* cancelButton_; | 52 | QPushButton* cancelButton_; |
| 53 | QPushButton* okButton_; | ||
| 48 | std::map<Command::Action, QPushButton*> actions_; | 54 | std::map<Command::Action, QPushButton*> actions_; |
| 55 | QDialogButtonBox* dialogButtons_; | ||
| 49 | QBoxLayout* layout_; | 56 | QBoxLayout* layout_; |
| 50 | }; | 57 | }; |
| 51 | } | 58 | } |
Swift