+ issue #0000953: No scroll bar on preferences dialog window
This commit is contained in:
parent
53816ba779
commit
cea0daa5e6
|
@ -23,6 +23,8 @@
|
||||||
|
|
||||||
#include "PreCompiled.h"
|
#include "PreCompiled.h"
|
||||||
#ifndef _PreComp_
|
#ifndef _PreComp_
|
||||||
|
# include <QEvent>
|
||||||
|
# include <QGridLayout>
|
||||||
# include <QPushButton>
|
# include <QPushButton>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -25,14 +25,18 @@
|
||||||
#ifndef _PreComp_
|
#ifndef _PreComp_
|
||||||
# include <cstring>
|
# include <cstring>
|
||||||
# include <algorithm>
|
# include <algorithm>
|
||||||
|
# include <QApplication>
|
||||||
# include <QDebug>
|
# include <QDebug>
|
||||||
|
# include <QDesktopWidget>
|
||||||
# include <QMessageBox>
|
# include <QMessageBox>
|
||||||
|
# include <QScrollArea>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <Base/Exception.h>
|
#include <Base/Exception.h>
|
||||||
#include <Base/Console.h>
|
#include <Base/Console.h>
|
||||||
|
|
||||||
#include "DlgPreferencesImp.h"
|
#include "DlgPreferencesImp.h"
|
||||||
|
#include "ui_DlgPreferences.h"
|
||||||
#include "PropertyPage.h"
|
#include "PropertyPage.h"
|
||||||
#include "WidgetFactory.h"
|
#include "WidgetFactory.h"
|
||||||
#include "BitmapFactory.h"
|
#include "BitmapFactory.h"
|
||||||
|
@ -53,12 +57,13 @@ std::list<DlgPreferencesImp::TGroupPages> DlgPreferencesImp::_pages;
|
||||||
* TRUE to construct a modal dialog.
|
* TRUE to construct a modal dialog.
|
||||||
*/
|
*/
|
||||||
DlgPreferencesImp::DlgPreferencesImp( QWidget* parent, Qt::WFlags fl )
|
DlgPreferencesImp::DlgPreferencesImp( QWidget* parent, Qt::WFlags fl )
|
||||||
: QDialog(parent, fl)
|
: QDialog(parent, fl), ui(new Ui_DlgPreferences), canEmbedScrollArea(true)
|
||||||
{
|
{
|
||||||
this->setupUi(this);
|
ui->setupUi(this);
|
||||||
connect(buttonBox, SIGNAL (helpRequested()),
|
|
||||||
|
connect(ui->buttonBox, SIGNAL (helpRequested()),
|
||||||
getMainWindow(), SLOT (whatsThis()));
|
getMainWindow(), SLOT (whatsThis()));
|
||||||
connect(listBox, SIGNAL(currentItemChanged(QListWidgetItem *, QListWidgetItem *)),
|
connect(ui->listBox, SIGNAL(currentItemChanged(QListWidgetItem *, QListWidgetItem *)),
|
||||||
this, SLOT(changeGroup(QListWidgetItem *, QListWidgetItem*)));
|
this, SLOT(changeGroup(QListWidgetItem *, QListWidgetItem*)));
|
||||||
|
|
||||||
setupPages();
|
setupPages();
|
||||||
|
@ -78,10 +83,10 @@ void DlgPreferencesImp::setupPages()
|
||||||
GetWidgetFactorySupplier();
|
GetWidgetFactorySupplier();
|
||||||
for (std::list<TGroupPages>::iterator it = _pages.begin(); it != _pages.end(); ++it) {
|
for (std::list<TGroupPages>::iterator it = _pages.begin(); it != _pages.end(); ++it) {
|
||||||
QTabWidget* tabWidget = new QTabWidget;
|
QTabWidget* tabWidget = new QTabWidget;
|
||||||
this->tabWidgetStack->addWidget(tabWidget);
|
ui->tabWidgetStack->addWidget(tabWidget);
|
||||||
|
|
||||||
QByteArray group = it->first.c_str();
|
QByteArray group = it->first.c_str();
|
||||||
QListWidgetItem *item = new QListWidgetItem(listBox);
|
QListWidgetItem *item = new QListWidgetItem(ui->listBox);
|
||||||
item->setData(Qt::UserRole, QVariant(group));
|
item->setData(Qt::UserRole, QVariant(group));
|
||||||
item->setText(QObject::tr(group.constData()));
|
item->setText(QObject::tr(group.constData()));
|
||||||
std::string fileName = it->first;
|
std::string fileName = it->first;
|
||||||
|
@ -116,14 +121,14 @@ void DlgPreferencesImp::setupPages()
|
||||||
}
|
}
|
||||||
|
|
||||||
// show the first group
|
// show the first group
|
||||||
listBox->setCurrentRow(0);
|
ui->listBox->setCurrentRow(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DlgPreferencesImp::changeGroup(QListWidgetItem *current, QListWidgetItem *previous)
|
void DlgPreferencesImp::changeGroup(QListWidgetItem *current, QListWidgetItem *previous)
|
||||||
{
|
{
|
||||||
if (!current)
|
if (!current)
|
||||||
current = previous;
|
current = previous;
|
||||||
tabWidgetStack->setCurrentIndex(listBox->row(current));
|
ui->tabWidgetStack->setCurrentIndex(ui->listBox->row(current));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -175,12 +180,12 @@ void DlgPreferencesImp::removePage(const std::string& className, const std::stri
|
||||||
*/
|
*/
|
||||||
void DlgPreferencesImp::activateGroupPage(const QString& group, int index)
|
void DlgPreferencesImp::activateGroupPage(const QString& group, int index)
|
||||||
{
|
{
|
||||||
int ct = listBox->count();
|
int ct = ui->listBox->count();
|
||||||
for (int i=0; i<ct; i++) {
|
for (int i=0; i<ct; i++) {
|
||||||
QListWidgetItem* item = listBox->item(i);
|
QListWidgetItem* item = ui->listBox->item(i);
|
||||||
if (item->data(Qt::UserRole).toString() == group) {
|
if (item->data(Qt::UserRole).toString() == group) {
|
||||||
listBox->setCurrentItem(item);
|
ui->listBox->setCurrentItem(item);
|
||||||
QTabWidget* tabWidget = (QTabWidget*)tabWidgetStack->widget(i);
|
QTabWidget* tabWidget = (QTabWidget*)ui->tabWidgetStack->widget(i);
|
||||||
tabWidget->setCurrentIndex(index);
|
tabWidget->setCurrentIndex(index);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -197,15 +202,15 @@ void DlgPreferencesImp::accept()
|
||||||
|
|
||||||
void DlgPreferencesImp::on_buttonBox_clicked(QAbstractButton* btn)
|
void DlgPreferencesImp::on_buttonBox_clicked(QAbstractButton* btn)
|
||||||
{
|
{
|
||||||
if (buttonBox->standardButton(btn) == QDialogButtonBox::Apply)
|
if (ui->buttonBox->standardButton(btn) == QDialogButtonBox::Apply)
|
||||||
applyChanges();
|
applyChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DlgPreferencesImp::applyChanges()
|
void DlgPreferencesImp::applyChanges()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
for (int i=0; i<tabWidgetStack->count(); i++) {
|
for (int i=0; i<ui->tabWidgetStack->count(); i++) {
|
||||||
QTabWidget* tabWidget = (QTabWidget*)tabWidgetStack->widget(i);
|
QTabWidget* tabWidget = (QTabWidget*)ui->tabWidgetStack->widget(i);
|
||||||
for (int j=0; j<tabWidget->count(); j++) {
|
for (int j=0; j<tabWidget->count(); j++) {
|
||||||
QWidget* page = tabWidget->widget(j);
|
QWidget* page = tabWidget->widget(j);
|
||||||
int index = page->metaObject()->indexOfMethod("checkSettings()");
|
int index = page->metaObject()->indexOfMethod("checkSettings()");
|
||||||
|
@ -213,8 +218,9 @@ void DlgPreferencesImp::applyChanges()
|
||||||
if (index >= 0) {
|
if (index >= 0) {
|
||||||
page->qt_metacall(QMetaObject::InvokeMetaMethod, index, 0);
|
page->qt_metacall(QMetaObject::InvokeMetaMethod, index, 0);
|
||||||
}
|
}
|
||||||
} catch (const Base::Exception& e) {
|
}
|
||||||
listBox->setCurrentRow(i);
|
catch (const Base::Exception& e) {
|
||||||
|
ui->listBox->setCurrentRow(i);
|
||||||
tabWidget->setCurrentIndex(j);
|
tabWidget->setCurrentIndex(j);
|
||||||
QMessageBox::warning(this, tr("Wrong parameter"), QString::fromAscii(e.what()));
|
QMessageBox::warning(this, tr("Wrong parameter"), QString::fromAscii(e.what()));
|
||||||
throw;
|
throw;
|
||||||
|
@ -226,8 +232,8 @@ void DlgPreferencesImp::applyChanges()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i=0; i<tabWidgetStack->count(); i++) {
|
for (int i=0; i<ui->tabWidgetStack->count(); i++) {
|
||||||
QTabWidget* tabWidget = (QTabWidget*)tabWidgetStack->widget(i);
|
QTabWidget* tabWidget = (QTabWidget*)ui->tabWidgetStack->widget(i);
|
||||||
for (int j=0; j<tabWidget->count(); j++) {
|
for (int j=0; j<tabWidget->count(); j++) {
|
||||||
PreferencePage* page = qobject_cast<PreferencePage*>(tabWidget->widget(j));
|
PreferencePage* page = qobject_cast<PreferencePage*>(tabWidget->widget(j));
|
||||||
if (page)
|
if (page)
|
||||||
|
@ -236,21 +242,47 @@ void DlgPreferencesImp::applyChanges()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DlgPreferencesImp::showEvent(QShowEvent* ev)
|
||||||
|
{
|
||||||
|
canEmbedScrollArea = false;
|
||||||
|
QDialog::showEvent(ev);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DlgPreferencesImp::resizeEvent(QResizeEvent* ev)
|
||||||
|
{
|
||||||
|
if (canEmbedScrollArea) {
|
||||||
|
// embed the widget stack into a scroll area if the size is
|
||||||
|
// bigger than the available desktop
|
||||||
|
int maxHeight = QApplication::desktop()->height();
|
||||||
|
int maxWidth = QApplication::desktop()->width();
|
||||||
|
if (height() > maxHeight || width() > maxWidth) {
|
||||||
|
canEmbedScrollArea = false;
|
||||||
|
ui->hboxLayout->removeWidget(ui->tabWidgetStack);
|
||||||
|
QScrollArea* scrollArea = new QScrollArea(this);
|
||||||
|
scrollArea->setFrameShape(QFrame::NoFrame);
|
||||||
|
scrollArea->setWidgetResizable(true);
|
||||||
|
scrollArea->setWidget(ui->tabWidgetStack);
|
||||||
|
ui->hboxLayout->addWidget(scrollArea);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
QDialog::resizeEvent(ev);
|
||||||
|
}
|
||||||
|
|
||||||
void DlgPreferencesImp::changeEvent(QEvent *e)
|
void DlgPreferencesImp::changeEvent(QEvent *e)
|
||||||
{
|
{
|
||||||
if (e->type() == QEvent::LanguageChange) {
|
if (e->type() == QEvent::LanguageChange) {
|
||||||
retranslateUi(this);
|
ui->retranslateUi(this);
|
||||||
// update the widgets' tabs
|
// update the widgets' tabs
|
||||||
for (int i=0; i<tabWidgetStack->count(); i++) {
|
for (int i=0; i<ui->tabWidgetStack->count(); i++) {
|
||||||
QTabWidget* tabWidget = (QTabWidget*)tabWidgetStack->widget(i);
|
QTabWidget* tabWidget = (QTabWidget*)ui->tabWidgetStack->widget(i);
|
||||||
for (int j=0; j<tabWidget->count(); j++) {
|
for (int j=0; j<tabWidget->count(); j++) {
|
||||||
QWidget* page = tabWidget->widget(j);
|
QWidget* page = tabWidget->widget(j);
|
||||||
tabWidget->setTabText(j, page->windowTitle());
|
tabWidget->setTabText(j, page->windowTitle());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// update the items' text
|
// update the items' text
|
||||||
for (int i=0; i<listBox->count(); i++) {
|
for (int i=0; i<ui->listBox->count(); i++) {
|
||||||
QListWidgetItem *item = listBox->item(i);
|
QListWidgetItem *item = ui->listBox->item(i);
|
||||||
QByteArray group = item->data(Qt::UserRole).toByteArray();
|
QByteArray group = item->data(Qt::UserRole).toByteArray();
|
||||||
item->setText(QObject::tr(group.constData()));
|
item->setText(QObject::tr(group.constData()));
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,12 +24,15 @@
|
||||||
#ifndef GUI_DIALOG_DLGPREFERENCESIMP_H
|
#ifndef GUI_DIALOG_DLGPREFERENCESIMP_H
|
||||||
#define GUI_DIALOG_DLGPREFERENCESIMP_H
|
#define GUI_DIALOG_DLGPREFERENCESIMP_H
|
||||||
|
|
||||||
#include <Gui/ui_DlgPreferences.h>
|
#include <QDialog>
|
||||||
|
|
||||||
|
class QAbstractButton;
|
||||||
|
class QListWidgetItem;
|
||||||
|
|
||||||
namespace Gui {
|
namespace Gui {
|
||||||
namespace Dialog {
|
namespace Dialog {
|
||||||
class PreferencePage;
|
class PreferencePage;
|
||||||
|
class Ui_DlgPreferences;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class implements a dialog containing several preference pages.
|
* This class implements a dialog containing several preference pages.
|
||||||
|
@ -101,7 +104,7 @@ class PreferencePage;
|
||||||
* \see PrefWidget
|
* \see PrefWidget
|
||||||
* \author Werner Mayer, Jürgen Riegel
|
* \author Werner Mayer, Jürgen Riegel
|
||||||
*/
|
*/
|
||||||
class GuiExport DlgPreferencesImp : public QDialog,public Ui_DlgPreferences
|
class GuiExport DlgPreferencesImp : public QDialog
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
@ -109,7 +112,7 @@ public:
|
||||||
static void addPage(const std::string& className, const std::string& group);
|
static void addPage(const std::string& className, const std::string& group);
|
||||||
static void removePage(const std::string& className, const std::string& group);
|
static void removePage(const std::string& className, const std::string& group);
|
||||||
|
|
||||||
DlgPreferencesImp( QWidget* parent = 0, Qt::WFlags fl = 0 );
|
DlgPreferencesImp(QWidget* parent = 0, Qt::WFlags fl = 0);
|
||||||
~DlgPreferencesImp();
|
~DlgPreferencesImp();
|
||||||
|
|
||||||
void accept();
|
void accept();
|
||||||
|
@ -117,6 +120,8 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void changeEvent(QEvent *e);
|
void changeEvent(QEvent *e);
|
||||||
|
void showEvent(QShowEvent*);
|
||||||
|
void resizeEvent(QResizeEvent*);
|
||||||
|
|
||||||
protected Q_SLOTS:
|
protected Q_SLOTS:
|
||||||
void changeGroup(QListWidgetItem *current, QListWidgetItem *previous);
|
void changeGroup(QListWidgetItem *current, QListWidgetItem *previous);
|
||||||
|
@ -133,6 +138,8 @@ private:
|
||||||
typedef std::pair<std::string, std::list<std::string> > TGroupPages;
|
typedef std::pair<std::string, std::list<std::string> > TGroupPages;
|
||||||
static std::list<TGroupPages> _pages; /**< Name of all registered preference pages */
|
static std::list<TGroupPages> _pages; /**< Name of all registered preference pages */
|
||||||
bool invalidParameter;
|
bool invalidParameter;
|
||||||
|
bool canEmbedScrollArea;
|
||||||
|
Ui_DlgPreferences* ui;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Dialog
|
} // namespace Dialog
|
||||||
|
|
Loading…
Reference in New Issue
Block a user