Better default window layout.

This commit is contained in:
Leonardo Zide 2017-02-06 09:06:52 -08:00
parent 48d252bfb3
commit 77f4cf8de4
4 changed files with 60 additions and 21 deletions

View file

@ -98,6 +98,7 @@ void lcMainWindow::CreateWidgets()
move(QPoint(200, 200)); move(QPoint(200, 200));
restoreGeometry(Settings.value("Geometry").toByteArray()); restoreGeometry(Settings.value("Geometry").toByteArray());
restoreState(Settings.value("State").toByteArray()); restoreState(Settings.value("State").toByteArray());
mPartSelectionWidget->LoadState(Settings);
Settings.endGroup(); Settings.endGroup();
} }
@ -575,7 +576,7 @@ void lcMainWindow::CreateToolBars()
mPartsToolBar = new QDockWidget(tr("Parts"), this); mPartsToolBar = new QDockWidget(tr("Parts"), this);
mPartsToolBar->setObjectName("PartsToolbar"); mPartsToolBar->setObjectName("PartsToolbar");
mPartSelectionWidget = new lcPartSelectionWidget(this); mPartSelectionWidget = new lcPartSelectionWidget(mPartsToolBar);
mPartsToolBar->setWidget(mPartSelectionWidget); mPartsToolBar->setWidget(mPartSelectionWidget);
addDockWidget(Qt::RightDockWidgetArea, mPartsToolBar); addDockWidget(Qt::RightDockWidgetArea, mPartsToolBar);
@ -613,9 +614,9 @@ void lcMainWindow::CreateToolBars()
mTimelineToolBar->setWidget(mTimelineWidget); mTimelineToolBar->setWidget(mTimelineWidget);
addDockWidget(Qt::RightDockWidgetArea, mTimelineToolBar); addDockWidget(Qt::RightDockWidgetArea, mTimelineToolBar);
tabifyDockWidget(mColorsToolBar, mPropertiesToolBar); tabifyDockWidget(mPartsToolBar, mPropertiesToolBar);
tabifyDockWidget(mPropertiesToolBar, mTimelineToolBar); tabifyDockWidget(mPropertiesToolBar, mTimelineToolBar);
mColorsToolBar->raise(); mPartsToolBar->raise();
} }
void lcMainWindow::CreateStatusBar() void lcMainWindow::CreateStatusBar()
@ -636,20 +637,21 @@ void lcMainWindow::CreateStatusBar()
StatusBar->addPermanentWidget(mStatusTimeLabel); StatusBar->addPermanentWidget(mStatusTimeLabel);
} }
void lcMainWindow::closeEvent(QCloseEvent *event) void lcMainWindow::closeEvent(QCloseEvent* Event)
{ {
if (SaveProjectIfModified()) if (SaveProjectIfModified())
{ {
event->accept(); Event->accept();
QSettings settings; QSettings Settings;
settings.beginGroup("MainWindow"); Settings.beginGroup("MainWindow");
settings.setValue("Geometry", saveGeometry()); Settings.setValue("Geometry", saveGeometry());
settings.setValue("State", saveState()); Settings.setValue("State", saveState());
settings.endGroup(); mPartSelectionWidget->SaveState(Settings);
Settings.endGroup();
} }
else else
event->ignore(); Event->ignore();
} }
void lcMainWindow::dragEnterEvent(QDragEnterEvent* Event) void lcMainWindow::dragEnterEvent(QDragEnterEvent* Event)

View file

@ -537,18 +537,14 @@ lcPartSelectionWidget::lcPartSelectionWidget(QWidget* Parent)
: QWidget(Parent), mFilterAction(NULL) : QWidget(Parent), mFilterAction(NULL)
{ {
mSplitter = new QSplitter(this); mSplitter = new QSplitter(this);
mSplitter->setOrientation(Qt::Vertical);
mCategoriesWidget = new QTreeWidget(mSplitter); mCategoriesWidget = new QTreeWidget(mSplitter);
mCategoriesWidget->setHeaderHidden(true); mCategoriesWidget->setHeaderHidden(true);
mCategoriesWidget->setUniformRowHeights(true); mCategoriesWidget->setUniformRowHeights(true);
mCategoriesWidget->setRootIsDecorated(false); mCategoriesWidget->setRootIsDecorated(false);
QSizePolicy PartsWidgetPolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
PartsWidgetPolicy.setHorizontalStretch(1);
PartsWidgetPolicy.setVerticalStretch(1);
QWidget* PartsGroupWidget = new QWidget(mSplitter); QWidget* PartsGroupWidget = new QWidget(mSplitter);
PartsGroupWidget->setSizePolicy(PartsWidgetPolicy);
QVBoxLayout* PartsLayout = new QVBoxLayout(); QVBoxLayout* PartsLayout = new QVBoxLayout();
PartsLayout->setContentsMargins(0, 0, 0, 0); PartsLayout->setContentsMargins(0, 0, 0, 0);
@ -575,14 +571,51 @@ lcPartSelectionWidget::lcPartSelectionWidget(QWidget* Parent)
connect(mCategoriesWidget, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)), this, SLOT(CategoryChanged(QTreeWidgetItem*, QTreeWidgetItem*))); connect(mCategoriesWidget, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)), this, SLOT(CategoryChanged(QTreeWidgetItem*, QTreeWidgetItem*)));
UpdateCategories(); UpdateCategories();
mSplitter->setStretchFactor(0, 0);
mSplitter->setStretchFactor(1, 1);
connect(Parent, SIGNAL(dockLocationChanged(Qt::DockWidgetArea)), this, SLOT(DockLocationChanged(Qt::DockWidgetArea)));
qRegisterMetaTypeStreamOperators<QList<int> >("QList<int>");
}
void lcPartSelectionWidget::LoadState(QSettings& Settings)
{
QList<int> Sizes = Settings.value("PartSelectionSplitter").value<QList<int>>();
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<int> 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) void lcPartSelectionWidget::resizeEvent(QResizeEvent* Event)
{
if (((QDockWidget*)parent())->isFloating())
{ {
if (Event->size().width() > Event->size().height()) if (Event->size().width() > Event->size().height())
mSplitter->setOrientation(Qt::Horizontal); mSplitter->setOrientation(Qt::Horizontal);
else else
mSplitter->setOrientation(Qt::Vertical); mSplitter->setOrientation(Qt::Vertical);
}
QWidget::resizeEvent(Event); QWidget::resizeEvent(Event);
} }

View file

@ -162,6 +162,8 @@ public:
void SetDefaultPart(); void SetDefaultPart();
void UpdateModels(); void UpdateModels();
void UpdateCategories(); void UpdateCategories();
void LoadState(QSettings& Settings);
void SaveState(QSettings& Settings);
void SetColorIndex(int ColorIndex) void SetColorIndex(int ColorIndex)
{ {
@ -169,6 +171,7 @@ public:
} }
protected slots: protected slots:
void DockLocationChanged(Qt::DockWidgetArea Area);
void FilterChanged(const QString& Text); void FilterChanged(const QString& Text);
void FilterTriggered(); void FilterTriggered();
void CategoryChanged(QTreeWidgetItem* Current, QTreeWidgetItem* Previous); void CategoryChanged(QTreeWidgetItem* Current, QTreeWidgetItem* Previous);

View file

@ -42,6 +42,7 @@ lcQColorList::lcQColorList(QWidget *parent)
mPreferredHeight = TextHeight + 10 * mRows; mPreferredHeight = TextHeight + 10 * mRows;
setFocusPolicy(Qt::StrongFocus); setFocusPolicy(Qt::StrongFocus);
setMinimumHeight(TextHeight + 5 * mRows);
} }
lcQColorList::~lcQColorList() lcQColorList::~lcQColorList()