From 3741c9ad5c0cc6f92e4ed913d67b3b530882334e Mon Sep 17 00:00:00 2001 From: Tobias Markmann Date: Wed, 3 Jun 2015 08:19:49 +0200 Subject: 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 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 @@ /* - * Copyright (c) 2010-2014 Isode Limited. + * Copyright (c) 2010-2015 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ +#include + #include + #include -#include -#include -#include + #include #include +#include +#include + const int FormLayoutIndex = 1; namespace Swift { @@ -36,22 +40,25 @@ QtAdHocCommandWindow::QtAdHocCommandWindow(boost::shared_ptrsetFrameStyle(QFrame::Box|QFrame::Sunken); layout_->addWidget(errorLabel_); - QWidget* buttonsWidget = new QWidget(this); - layout_->addWidget(buttonsWidget); + dialogButtons_ = new QDialogButtonBox(this); + layout_->addWidget(dialogButtons_); - QBoxLayout* buttonsLayout = new QBoxLayout(QBoxLayout::LeftToRight, buttonsWidget); - cancelButton_ = new QPushButton(tr("Cancel"), buttonsWidget); - buttonsLayout->addWidget(cancelButton_); + dialogButtons_->setStandardButtons(QDialogButtonBox::Cancel | QDialogButtonBox::Ok); + okButton_ = dialogButtons_->button(QDialogButtonBox::Ok); + connect(okButton_, SIGNAL(clicked()), this, SLOT(close())); + cancelButton_ = dialogButtons_->button(QDialogButtonBox::Cancel); connect(cancelButton_, SIGNAL(clicked()), this, SLOT(handleCancelClicked())); - backButton_ = new QPushButton(tr("Back"), buttonsWidget); - buttonsLayout->addWidget(backButton_); - connect(backButton_, SIGNAL(clicked()), this, SLOT(handlePrevClicked())); - nextButton_ = new QPushButton(tr("Next"), buttonsWidget); - buttonsLayout->addWidget(nextButton_); - connect(nextButton_, SIGNAL(clicked()), this, SLOT(handleNextClicked())); - completeButton_ = new QPushButton(tr("Complete"), buttonsWidget); - buttonsLayout->addWidget(completeButton_); + // Buttons appear next to the Ok button, right of Cancel with YesRole + completeButton_ = dialogButtons_->addButton(tr("Complete"), QDialogButtonBox::YesRole); connect(completeButton_, SIGNAL(clicked()), this, SLOT(handleCompleteClicked())); + nextButton_ = dialogButtons_->addButton(tr("Next"), QDialogButtonBox::YesRole); + connect(nextButton_, SIGNAL(clicked()), this, SLOT(handleNextClicked())); + backButton_ = dialogButtons_->addButton(tr("Back"), QDialogButtonBox::YesRole); + connect(backButton_, SIGNAL(clicked()), this, SLOT(handlePrevClicked())); + + okButton_->setEnabled(false); + okButton_->hide(); + nextButton_->setEnabled(false); backButton_->setEnabled(false); completeButton_->setEnabled(false); @@ -143,9 +150,13 @@ void QtAdHocCommandWindow::setNoForm(bool andHide) { typedef std::pair ActionButton; void QtAdHocCommandWindow::setAvailableActions(Command::ref /*commandResult*/) { + okButton_->show(); + okButton_->setEnabled(true); foreach (ActionButton pair, actions_) { OutgoingAdHocCommandSession::ActionState state = command_->getActionState(pair.first); if (state & OutgoingAdHocCommandSession::Present) { + okButton_->hide(); + okButton_->setEnabled(false); pair.second->show(); } 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 @@ /* - * Copyright (c) 2010-2012 Isode Limited. + * Copyright (c) 2010-2015 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once -#include -#include +#include #include +#include +#include -#include #include +#include + class QBoxLayout; namespace Swift { @@ -23,6 +25,7 @@ namespace Swift { QtAdHocCommandWindow(boost::shared_ptr command); virtual ~QtAdHocCommandWindow(); virtual void setOnline(bool online); + private: void closeEvent(QCloseEvent* event); void handleNextStageReceived(Command::ref command); @@ -30,11 +33,13 @@ namespace Swift { void setForm(Form::ref); void setNoForm(bool andHide); void setAvailableActions(Command::ref commandResult); + private slots: void handleCancelClicked(); void handlePrevClicked(); void handleNextClicked(); void handleCompleteClicked(); + private: boost::shared_ptr command_; QtFormWidget* formWidget_; @@ -45,7 +50,9 @@ namespace Swift { QPushButton* nextButton_; QPushButton* completeButton_; QPushButton* cancelButton_; + QPushButton* okButton_; std::map actions_; + QDialogButtonBox* dialogButtons_; QBoxLayout* layout_; }; } -- cgit v0.10.2-6-g49f6