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));
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)

View file

@ -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,14 +571,51 @@ 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<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)
{
if (((QDockWidget*)parent())->isFloating())
{
if (Event->size().width() > Event->size().height())
mSplitter->setOrientation(Qt::Horizontal);
else
mSplitter->setOrientation(Qt::Vertical);
}
QWidget::resizeEvent(Event);
}

View file

@ -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);

View file

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