mirror of
				https://github.com/OpenMW/openmw.git
				synced 2025-10-30 02:56:44 +00:00 
			
		
		
		
	Rework widget layout of ExtendedCommandConfigurator
This commit is contained in:
		
							parent
							
								
									b8772c6902
								
							
						
					
					
						commit
						12bf3694bd
					
				
					 2 changed files with 16 additions and 24 deletions
				
			
		|  | @ -3,6 +3,7 @@ | ||||||
| #include <QPushButton> | #include <QPushButton> | ||||||
| #include <QGroupBox> | #include <QGroupBox> | ||||||
| #include <QCheckBox> | #include <QCheckBox> | ||||||
|  | #include <QLabel> | ||||||
| #include <QLayout> | #include <QLayout> | ||||||
| 
 | 
 | ||||||
| #include "../../model/world/commanddispatcher.hpp" | #include "../../model/world/commanddispatcher.hpp" | ||||||
|  | @ -39,10 +40,8 @@ CSVWorld::ExtendedCommandConfigurator::ExtendedCommandConfigurator(CSMDoc::Docum | ||||||
|     mCancelButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); |     mCancelButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); | ||||||
|     connect(mCancelButton, SIGNAL(clicked(bool)), this, SIGNAL(done())); |     connect(mCancelButton, SIGNAL(clicked(bool)), this, SIGNAL(done())); | ||||||
| 
 | 
 | ||||||
|     mButtonLayout = new QHBoxLayout(); |     mCommandTitle = new QLabel(this); | ||||||
|     mButtonLayout->setAlignment(Qt::AlignCenter); |     mCommandTitle->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); | ||||||
|     mButtonLayout->addWidget(mPerformButton); |  | ||||||
|     mButtonLayout->addWidget(mCancelButton); |  | ||||||
| 
 | 
 | ||||||
|     mTypeGroup = new QGroupBox(this); |     mTypeGroup = new QGroupBox(this); | ||||||
| 
 | 
 | ||||||
|  | @ -50,15 +49,12 @@ CSVWorld::ExtendedCommandConfigurator::ExtendedCommandConfigurator(CSMDoc::Docum | ||||||
|     groupLayout->setAlignment(Qt::AlignCenter); |     groupLayout->setAlignment(Qt::AlignCenter); | ||||||
|     mTypeGroup->setLayout(groupLayout); |     mTypeGroup->setLayout(groupLayout); | ||||||
| 
 | 
 | ||||||
|     QVBoxLayout *mainLayout = new QVBoxLayout(this); |     QHBoxLayout *mainLayout = new QHBoxLayout(this); | ||||||
|     mainLayout->setSizeConstraint(QLayout::SetNoConstraint); |     mainLayout->setSizeConstraint(QLayout::SetNoConstraint); | ||||||
|  |     mainLayout->addWidget(mCommandTitle); | ||||||
|     mainLayout->addWidget(mTypeGroup); |     mainLayout->addWidget(mTypeGroup); | ||||||
|     mainLayout->addLayout(mButtonLayout); |     mainLayout->addWidget(mPerformButton); | ||||||
| } |     mainLayout->addWidget(mCancelButton); | ||||||
| 
 |  | ||||||
| CSVWorld::ExtendedCommandConfigurator::~ExtendedCommandConfigurator() |  | ||||||
| { |  | ||||||
|     delete mButtonLayout; |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void CSVWorld::ExtendedCommandConfigurator::configure(CSVWorld::ExtendedCommandConfigurator::Mode mode, | void CSVWorld::ExtendedCommandConfigurator::configure(CSVWorld::ExtendedCommandConfigurator::Mode mode, | ||||||
|  | @ -67,7 +63,9 @@ void CSVWorld::ExtendedCommandConfigurator::configure(CSVWorld::ExtendedCommandC | ||||||
|     mMode = mode; |     mMode = mode; | ||||||
|     if (mMode != Mode_None) |     if (mMode != Mode_None) | ||||||
|     { |     { | ||||||
|         mTypeGroup->setTitle(getTypeGroupTitle(mMode)); |         QString title = (mMode == Mode_Delete) ? "Extended Delete" : "Extended Revert"; | ||||||
|  |         title.append(" from:"); | ||||||
|  |         mCommandTitle->setText(title); | ||||||
|         mCommandDispatcher->setSelection(selectedIds); |         mCommandDispatcher->setSelection(selectedIds); | ||||||
|         setupCheckBoxes(mCommandDispatcher->getExtendedTypes()); |         setupCheckBoxes(mCommandDispatcher->getExtendedTypes()); | ||||||
|         setupGroupLayout(); |         setupGroupLayout(); | ||||||
|  | @ -90,12 +88,6 @@ void CSVWorld::ExtendedCommandConfigurator::setupGroupLayout() | ||||||
|     int groupWidth = mTypeGroup->geometry().width(); |     int groupWidth = mTypeGroup->geometry().width(); | ||||||
|     QGridLayout *layout = qobject_cast<QGridLayout *>(mTypeGroup->layout()); |     QGridLayout *layout = qobject_cast<QGridLayout *>(mTypeGroup->layout()); | ||||||
| 
 | 
 | ||||||
|     // One row of checkboxes with enough space - the setup is over
 |  | ||||||
|     if (mNumUsedCheckBoxes > 0 && layout->rowCount() == 1 && groupWidth >= mTypeGroup->sizeHint().width()) |  | ||||||
|     { |  | ||||||
|         return; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     // Find the optimal number of rows to place the checkboxes within the available space
 |     // Find the optimal number of rows to place the checkboxes within the available space
 | ||||||
|     int divider = 1; |     int divider = 1; | ||||||
|     do |     do | ||||||
|  | @ -111,7 +103,7 @@ void CSVWorld::ExtendedCommandConfigurator::setupGroupLayout() | ||||||
|         CheckBoxMap::const_iterator end = mTypeCheckBoxes.end(); |         CheckBoxMap::const_iterator end = mTypeCheckBoxes.end(); | ||||||
|         for (; current != end; ++current) |         for (; current != end; ++current) | ||||||
|         { |         { | ||||||
|             if (current->first->isVisible()) |             if (counter < mNumUsedCheckBoxes) | ||||||
|             { |             { | ||||||
|                 int row = counter / itemsPerRow; |                 int row = counter / itemsPerRow; | ||||||
|                 int column = counter - (counter / itemsPerRow) * itemsPerRow; |                 int column = counter - (counter / itemsPerRow) * itemsPerRow; | ||||||
|  | @ -121,7 +113,7 @@ void CSVWorld::ExtendedCommandConfigurator::setupGroupLayout() | ||||||
|         } |         } | ||||||
|         divider *= 2; |         divider *= 2; | ||||||
|     } |     } | ||||||
|     while (groupWidth < mTypeGroup->sizeHint().width()); |     while (groupWidth < mTypeGroup->sizeHint().width() && divider <= mNumUsedCheckBoxes); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void CSVWorld::ExtendedCommandConfigurator::setupCheckBoxes(const std::vector<CSMWorld::UniversalId> &types) | void CSVWorld::ExtendedCommandConfigurator::setupCheckBoxes(const std::vector<CSMWorld::UniversalId> &types) | ||||||
|  | @ -133,7 +125,7 @@ void CSVWorld::ExtendedCommandConfigurator::setupCheckBoxes(const std::vector<CS | ||||||
|     { |     { | ||||||
|         for (int i = numTypes - numCheckBoxes; i > 0; --i) |         for (int i = numTypes - numCheckBoxes; i > 0; --i) | ||||||
|         { |         { | ||||||
|             mTypeCheckBoxes.insert(std::make_pair(new QCheckBox(this), CSMWorld::UniversalId::Type_None)); |             mTypeCheckBoxes.insert(std::make_pair(new QCheckBox(mTypeGroup), CSMWorld::UniversalId::Type_None)); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | @ -156,7 +148,7 @@ void CSVWorld::ExtendedCommandConfigurator::setupCheckBoxes(const std::vector<CS | ||||||
|             current->first->hide(); |             current->first->hide(); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|     mNumUsedCheckBoxes = counter - 1; |     mNumUsedCheckBoxes = numTypes; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void CSVWorld::ExtendedCommandConfigurator::performExtendedCommand() | void CSVWorld::ExtendedCommandConfigurator::performExtendedCommand() | ||||||
|  |  | ||||||
|  | @ -8,6 +8,7 @@ | ||||||
| class QPushButton; | class QPushButton; | ||||||
| class QGroupBox; | class QGroupBox; | ||||||
| class QCheckBox; | class QCheckBox; | ||||||
|  | class QLabel; | ||||||
| class QHBoxLayout; | class QHBoxLayout; | ||||||
| 
 | 
 | ||||||
| namespace CSMDoc | namespace CSMDoc | ||||||
|  | @ -35,7 +36,7 @@ namespace CSVWorld | ||||||
| 
 | 
 | ||||||
|             QPushButton *mPerformButton; |             QPushButton *mPerformButton; | ||||||
|             QPushButton *mCancelButton; |             QPushButton *mCancelButton; | ||||||
|             QHBoxLayout *mButtonLayout; |             QLabel *mCommandTitle; | ||||||
|             QGroupBox *mTypeGroup; |             QGroupBox *mTypeGroup; | ||||||
|             CheckBoxMap mTypeCheckBoxes; |             CheckBoxMap mTypeCheckBoxes; | ||||||
|             int mNumUsedCheckBoxes; |             int mNumUsedCheckBoxes; | ||||||
|  | @ -50,7 +51,6 @@ namespace CSVWorld | ||||||
|             ExtendedCommandConfigurator(CSMDoc::Document &document, |             ExtendedCommandConfigurator(CSMDoc::Document &document, | ||||||
|                                         const CSMWorld::UniversalId &id, |                                         const CSMWorld::UniversalId &id, | ||||||
|                                         QWidget *parent = 0); |                                         QWidget *parent = 0); | ||||||
|             virtual ~ExtendedCommandConfigurator(); |  | ||||||
| 
 | 
 | ||||||
|             void configure(Mode mode, const std::vector<std::string> &selectedIds); |             void configure(Mode mode, const std::vector<std::string> &selectedIds); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue