From 77f4cf8de4f49617965d776de56f8fa5a01e5e99 Mon Sep 17 00:00:00 2001 From: Leonardo Zide Date: Mon, 6 Feb 2017 09:06:52 -0800 Subject: [PATCH] Better default window layout. --- common/lc_mainwindow.cpp | 24 +++++++------- common/lc_partselectionwidget.cpp | 53 +++++++++++++++++++++++++------ common/lc_partselectionwidget.h | 3 ++ qt/lc_qcolorlist.cpp | 1 + 4 files changed, 60 insertions(+), 21 deletions(-) diff --git a/common/lc_mainwindow.cpp b/common/lc_mainwindow.cpp index 7d8ff734..a9acd522 100644 --- a/common/lc_mainwindow.cpp +++ b/common/lc_mainwindow.cpp @@ -98,6 +98,7 @@ void lcMainWindow::CreateWidgets() move(QPoint(200, 200)); restoreGeometry(Settings.value("Geometry").toByteArray()); restoreState(Settings.value("State").toByteArray()); + mPartSelectionWidget->LoadState(Settings); Settings.endGroup(); } @@ -575,7 +576,7 @@ void lcMainWindow::CreateToolBars() mPartsToolBar = new QDockWidget(tr("Parts"), this); mPartsToolBar->setObjectName("PartsToolbar"); - mPartSelectionWidget = new lcPartSelectionWidget(this); + mPartSelectionWidget = new lcPartSelectionWidget(mPartsToolBar); mPartsToolBar->setWidget(mPartSelectionWidget); addDockWidget(Qt::RightDockWidgetArea, mPartsToolBar); @@ -613,9 +614,9 @@ void lcMainWindow::CreateToolBars() mTimelineToolBar->setWidget(mTimelineWidget); addDockWidget(Qt::RightDockWidgetArea, mTimelineToolBar); - tabifyDockWidget(mColorsToolBar, mPropertiesToolBar); + tabifyDockWidget(mPartsToolBar, mPropertiesToolBar); tabifyDockWidget(mPropertiesToolBar, mTimelineToolBar); - mColorsToolBar->raise(); + mPartsToolBar->raise(); } void lcMainWindow::CreateStatusBar() @@ -636,20 +637,21 @@ void lcMainWindow::CreateStatusBar() StatusBar->addPermanentWidget(mStatusTimeLabel); } -void lcMainWindow::closeEvent(QCloseEvent *event) +void lcMainWindow::closeEvent(QCloseEvent* Event) { if (SaveProjectIfModified()) { - event->accept(); + Event->accept(); - QSettings settings; - settings.beginGroup("MainWindow"); - settings.setValue("Geometry", saveGeometry()); - settings.setValue("State", saveState()); - settings.endGroup(); + QSettings Settings; + Settings.beginGroup("MainWindow"); + Settings.setValue("Geometry", saveGeometry()); + Settings.setValue("State", saveState()); + mPartSelectionWidget->SaveState(Settings); + Settings.endGroup(); } else - event->ignore(); + Event->ignore(); } void lcMainWindow::dragEnterEvent(QDragEnterEvent* Event) diff --git a/common/lc_partselectionwidget.cpp b/common/lc_partselectionwidget.cpp index 80e351e0..e8cd2c90 100644 --- a/common/lc_partselectionwidget.cpp +++ b/common/lc_partselectionwidget.cpp @@ -537,18 +537,14 @@ lcPartSelectionWidget::lcPartSelectionWidget(QWidget* Parent) : QWidget(Parent), mFilterAction(NULL) { mSplitter = new QSplitter(this); + mSplitter->setOrientation(Qt::Vertical); mCategoriesWidget = new QTreeWidget(mSplitter); mCategoriesWidget->setHeaderHidden(true); mCategoriesWidget->setUniformRowHeights(true); mCategoriesWidget->setRootIsDecorated(false); - QSizePolicy PartsWidgetPolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); - PartsWidgetPolicy.setHorizontalStretch(1); - PartsWidgetPolicy.setVerticalStretch(1); - QWidget* PartsGroupWidget = new QWidget(mSplitter); - PartsGroupWidget->setSizePolicy(PartsWidgetPolicy); QVBoxLayout* PartsLayout = new QVBoxLayout(); PartsLayout->setContentsMargins(0, 0, 0, 0); @@ -575,15 +571,52 @@ lcPartSelectionWidget::lcPartSelectionWidget(QWidget* Parent) connect(mCategoriesWidget, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)), this, SLOT(CategoryChanged(QTreeWidgetItem*, QTreeWidgetItem*))); UpdateCategories(); + + mSplitter->setStretchFactor(0, 0); + mSplitter->setStretchFactor(1, 1); + + connect(Parent, SIGNAL(dockLocationChanged(Qt::DockWidgetArea)), this, SLOT(DockLocationChanged(Qt::DockWidgetArea))); + + qRegisterMetaTypeStreamOperators >("QList"); +} + +void lcPartSelectionWidget::LoadState(QSettings& Settings) +{ + QList Sizes = Settings.value("PartSelectionSplitter").value>(); + + if (Sizes.size() != 2) + { + int Length = mSplitter->orientation() == Qt::Horizontal ? mSplitter->width() : mSplitter->height(); + Sizes << Length / 3 << 2 * Length / 3; + } + + mSplitter->setSizes(Sizes); +} + +void lcPartSelectionWidget::SaveState(QSettings& Settings) +{ + QList Sizes = mSplitter->sizes(); + Settings.setValue("PartSelectionSplitter", QVariant::fromValue(Sizes)); +} + +void lcPartSelectionWidget::DockLocationChanged(Qt::DockWidgetArea Area) +{ + if (Area == Qt::LeftDockWidgetArea || Area == Qt::RightDockWidgetArea) + mSplitter->setOrientation(Qt::Vertical); + else + mSplitter->setOrientation(Qt::Horizontal); } void lcPartSelectionWidget::resizeEvent(QResizeEvent* Event) { - if (Event->size().width() > Event->size().height()) - mSplitter->setOrientation(Qt::Horizontal); - else - mSplitter->setOrientation(Qt::Vertical); - + if (((QDockWidget*)parent())->isFloating()) + { + if (Event->size().width() > Event->size().height()) + mSplitter->setOrientation(Qt::Horizontal); + else + mSplitter->setOrientation(Qt::Vertical); + } + QWidget::resizeEvent(Event); } diff --git a/common/lc_partselectionwidget.h b/common/lc_partselectionwidget.h index 69f6be07..29dd8a98 100644 --- a/common/lc_partselectionwidget.h +++ b/common/lc_partselectionwidget.h @@ -162,6 +162,8 @@ public: void SetDefaultPart(); void UpdateModels(); void UpdateCategories(); + void LoadState(QSettings& Settings); + void SaveState(QSettings& Settings); void SetColorIndex(int ColorIndex) { @@ -169,6 +171,7 @@ public: } protected slots: + void DockLocationChanged(Qt::DockWidgetArea Area); void FilterChanged(const QString& Text); void FilterTriggered(); void CategoryChanged(QTreeWidgetItem* Current, QTreeWidgetItem* Previous); diff --git a/qt/lc_qcolorlist.cpp b/qt/lc_qcolorlist.cpp index ad4110c9..7b7bf656 100644 --- a/qt/lc_qcolorlist.cpp +++ b/qt/lc_qcolorlist.cpp @@ -42,6 +42,7 @@ lcQColorList::lcQColorList(QWidget *parent) mPreferredHeight = TextHeight + 10 * mRows; setFocusPolicy(Qt::StrongFocus); + setMinimumHeight(TextHeight + 5 * mRows); } lcQColorList::~lcQColorList()