Gui: set minimum width of preferences dialog to avoid to truncate or hide controls
This commit is contained in:
@@ -329,6 +329,7 @@ void DlgPreferencesImp::createPageInGroup(PreferencesPageItem *groupItem, const
|
||||
}
|
||||
|
||||
pages->addWidget(page);
|
||||
addSizeHint(page);
|
||||
}
|
||||
catch (const Base::Exception& e) {
|
||||
Base::Console().Error("Base exception thrown for '%s'\n", pageName.c_str());
|
||||
@@ -339,6 +340,29 @@ void DlgPreferencesImp::createPageInGroup(PreferencesPageItem *groupItem, const
|
||||
}
|
||||
}
|
||||
|
||||
void DlgPreferencesImp::addSizeHint(QWidget* page)
|
||||
{
|
||||
_sizeHintOfPages = _sizeHintOfPages.expandedTo(page->minimumSizeHint());
|
||||
}
|
||||
|
||||
int DlgPreferencesImp::minimumPageWidth() const
|
||||
{
|
||||
return _sizeHintOfPages.width();
|
||||
}
|
||||
|
||||
int DlgPreferencesImp::minimumDialogWidth(int pageWidth) const
|
||||
{
|
||||
QSize size = ui->groupWidgetStack->sizeHint();
|
||||
int diff = pageWidth - size.width();
|
||||
int dw = width();
|
||||
if (diff > 0) {
|
||||
const int offset = 2;
|
||||
dw += diff + offset;
|
||||
}
|
||||
|
||||
return dw;
|
||||
}
|
||||
|
||||
void DlgPreferencesImp::updatePageDependentWidgets()
|
||||
{
|
||||
auto currentPageItem = getCurrentPage();
|
||||
@@ -734,6 +758,12 @@ void DlgPreferencesImp::showEvent(QShowEvent* ev)
|
||||
resize(width(), maxStartHeight);
|
||||
move(x(), heightDifference / 2);
|
||||
}
|
||||
|
||||
// if the expanded dialog occupies less than 50% of the screen
|
||||
int mw = minimumDialogWidth(minimumPageWidth());
|
||||
if (availableSize.width() > 2 * mw) {
|
||||
resize(mw, height());
|
||||
}
|
||||
}
|
||||
|
||||
void DlgPreferencesImp::onPageSelected(const QModelIndex& index)
|
||||
|
||||
@@ -181,6 +181,10 @@ private:
|
||||
void updatePageDependentWidgets();
|
||||
|
||||
QPixmap loadIconForGroup(const std::string& name) const;
|
||||
|
||||
void addSizeHint(QWidget*);
|
||||
int minimumPageWidth() const;
|
||||
int minimumDialogWidth(int) const;
|
||||
//@}
|
||||
|
||||
private:
|
||||
@@ -189,6 +193,7 @@ private:
|
||||
static std::list<TGroupPages> _pages; /**< Name of all registered preference pages */
|
||||
|
||||
QStandardItemModel _model;
|
||||
QSize _sizeHintOfPages;
|
||||
|
||||
struct Group {
|
||||
std::string iconName;
|
||||
|
||||
Reference in New Issue
Block a user