From: Peter Penz Date: Sun, 11 Mar 2007 14:41:09 +0000 (+0000) Subject: assure that the iconsview settings-dialog fits on a 800 x 600 screen X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/commitdiff_plain/57e674992771b9dc885097d1ea1b50e5c41cd5a4?ds=inline assure that the iconsview settings-dialog fits on a 800 x 600 screen svn path=/trunk/KDE/kdebase/apps/; revision=641493 --- diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e73965491..b3edb92c2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -29,6 +29,7 @@ set(dolphin_SRCS filterbar.cpp generalsettingspage.cpp generalviewsettingspage.cpp + iconsizedialog.cpp iconsviewsettingspage.cpp infosidebarpage.cpp main.cpp diff --git a/src/iconsizedialog.cpp b/src/iconsizedialog.cpp new file mode 100644 index 000000000..4b4eb48de --- /dev/null +++ b/src/iconsizedialog.cpp @@ -0,0 +1,188 @@ +/*************************************************************************** + * Copyright (C) 2006 by Peter Penz * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#include "iconsizedialog.h" + +#include "dolphinsettings.h" +#include "pixmapviewer.h" + +#include "dolphin_iconsmodesettings.h" + +#include +#include +#include + +#include +#include +#include +#include + +IconSizeDialog::IconSizeDialog(QWidget* parent) : + KDialog(parent), + m_iconSize(0), + m_previewSize(0), + m_iconSizeSlider(0), + m_iconSizeViewer(0), + m_previewSizeSlider(0), + m_previewSizeViewer(0) + +{ + IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings(); + Q_ASSERT(settings != 0); + m_iconSize = settings->iconSize(); + m_previewSize = settings->previewSize(); + + const int spacing = KDialog::spacingHint(); + + setCaption(i18n("Change Icon and Preview Size")); + setButtons(Ok|Cancel); + setDefaultButton(Ok); + + QWidget* main = new QWidget(); + QHBoxLayout* topLayout = new QHBoxLayout(); + + // create 'Icon Size' group including slider and preview + QGroupBox* iconSizeBox = new QGroupBox(i18n("Icon Size"), main); + + const QColor iconBackgroundColor(KGlobalSettings::baseColor()); + + KHBox* iconSizeHBox = new KHBox(iconSizeBox); + iconSizeHBox->setSpacing(spacing); + new QLabel(i18n("Small"), iconSizeHBox); + m_iconSizeSlider = new QSlider(0, 5, 1, 0, Qt::Horizontal, iconSizeHBox); + m_iconSizeSlider->setValue(sliderValue(settings->iconSize())); + m_iconSizeSlider->setTickmarks(QSlider::TicksBelow); + connect(m_iconSizeSlider, SIGNAL(valueChanged(int)), + this, SLOT(updateIconSize(int))); + new QLabel(i18n("Large"), iconSizeHBox); + + m_iconSizeViewer = new PixmapViewer(iconSizeBox); + m_iconSizeViewer->setMinimumWidth(K3Icon::SizeEnormous); + m_iconSizeViewer->setFixedHeight(K3Icon::SizeEnormous); + m_iconSizeViewer->setEraseColor(iconBackgroundColor); + updateIconSize(m_iconSizeSlider->value()); + + QVBoxLayout* iconSizeLayout = new QVBoxLayout(iconSizeBox); + iconSizeLayout->addWidget(iconSizeHBox); + iconSizeLayout->addWidget(m_iconSizeViewer); + + // create 'Preview Size' group including slider and preview + QGroupBox* previewSizeBox = new QGroupBox(i18n("Preview Size"), main); + + KHBox* previewSizeHBox = new KHBox(previewSizeBox); + previewSizeHBox->setSpacing(spacing); + new QLabel(i18n("Small"), previewSizeHBox); + m_previewSizeSlider = new QSlider(0, 5, 1, 0, Qt::Horizontal, previewSizeHBox); + m_previewSizeSlider->setValue(sliderValue(settings->previewSize())); + m_previewSizeSlider->setTickmarks(QSlider::TicksBelow); + connect(m_previewSizeSlider, SIGNAL(valueChanged(int)), + this, SLOT(updatePreviewSize(int))); + new QLabel(i18n("Large"), previewSizeHBox); + + m_previewSizeViewer = new PixmapViewer(previewSizeBox); + m_previewSizeViewer->setMinimumWidth(K3Icon::SizeEnormous); + m_previewSizeViewer->setFixedHeight(K3Icon::SizeEnormous); + m_previewSizeViewer->setEraseColor(iconBackgroundColor); + updatePreviewSize(m_previewSizeSlider->value()); + + QVBoxLayout* previewSizeLayout = new QVBoxLayout(previewSizeBox); + previewSizeLayout->addWidget(previewSizeHBox); + previewSizeLayout->addWidget(m_previewSizeViewer); + + topLayout->addWidget(iconSizeBox); + topLayout->addWidget(previewSizeBox); + main->setLayout(topLayout); + setMainWidget(main); +} + +IconSizeDialog::~IconSizeDialog() +{ +} + +void IconSizeDialog::slotButtonClicked(int button) +{ + if (button == Ok) { + m_iconSize = iconSize(m_iconSizeSlider->value()); + + m_previewSize = iconSize(m_previewSizeSlider->value()); + if (m_previewSize < m_iconSize) { + // assure that the preview size is never smaller than the icon size + m_previewSize = m_iconSize; + } + } + + KDialog::slotButtonClicked(button); +} + +void IconSizeDialog::updateIconSize(int value) +{ + KIconLoader iconLoader; + m_iconSizeViewer->setPixmap(iconLoader.loadIcon("folder", K3Icon::Desktop, iconSize(value))); + + if (m_previewSizeSlider != 0) { + int previewSizeValue = m_previewSizeSlider->value(); + if (previewSizeValue < value) { + // assure that the preview size is never smaller than the icon size + previewSizeValue = value; + } + updatePreviewSize(previewSizeValue); + } +} + +void IconSizeDialog::updatePreviewSize(int value) +{ + KIconLoader iconLoader; + const int iconSizeValue = m_iconSizeSlider->value(); + if (value < iconSizeValue) { + // assure that the preview size is never smaller than the icon size + value = iconSizeValue; + } + m_previewSizeViewer->setPixmap(iconLoader.loadIcon("preview", K3Icon::Desktop, iconSize(value))); +} + +int IconSizeDialog::iconSize(int sliderValue) const +{ + int size = K3Icon::SizeMedium; + switch (sliderValue) { + case 0: size = K3Icon::SizeSmall; break; + case 1: size = K3Icon::SizeSmallMedium; break; + case 2: size = K3Icon::SizeMedium; break; + case 3: size = K3Icon::SizeLarge; break; + case 4: size = K3Icon::SizeHuge; break; + case 5: size = K3Icon::SizeEnormous; break; + } + return size; +} + +int IconSizeDialog::sliderValue(int iconSize) const +{ + int value = 0; + switch (iconSize) { + case K3Icon::SizeSmall: value = 0; break; + case K3Icon::SizeSmallMedium: value = 1; break; + case K3Icon::SizeMedium: value = 2; break; + case K3Icon::SizeLarge: value = 3; break; + case K3Icon::SizeHuge: value = 4; break; + case K3Icon::SizeEnormous: value = 5; break; + default: break; + } + return value; +} + +#include "iconsizedialog.moc" diff --git a/src/iconsizedialog.h b/src/iconsizedialog.h new file mode 100644 index 000000000..9fffa3dfc --- /dev/null +++ b/src/iconsizedialog.h @@ -0,0 +1,76 @@ +/*************************************************************************** + * Copyright (C) 2006 by Peter Penz * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#ifndef ICONSIZEDIALOG_H +#define ICONSIZEDIALOG_H + +#include + +class QSlider; +class PixmapViewer; + +/** + * @brief Allows to adjust the size for icons and previews. + * + * Default usage: + * \code + * IconSizeDialog dialog(this); + * if (dialog.exec() == QDialog::Accepted) { + * const int iconSize = dialog.iconSize(); + * const int previewSize = dialog.previewSize(); + * // ... + * } + * \endcode + */ +class IconSizeDialog : public KDialog +{ + Q_OBJECT + +public: + explicit IconSizeDialog(QWidget* parent); + virtual ~IconSizeDialog(); + + int iconSize() const { return m_iconSize; } + int previewSize() const { return m_previewSize; } + +protected slots: + virtual void slotButtonClicked(int button); + +private slots: + void updateIconSize(int value); + void updatePreviewSize(int value); + +private: + /** Returns the icon size for the given slider value. */ + int iconSize(int sliderValue) const; + + /** Returns the slider value for the given icon size. */ + int sliderValue(int iconSize) const; + +private: + int m_iconSize; + int m_previewSize; + + QSlider* m_iconSizeSlider; + PixmapViewer* m_iconSizeViewer; + QSlider* m_previewSizeSlider; + PixmapViewer* m_previewSizeViewer; +}; + +#endif diff --git a/src/iconsviewsettingspage.cpp b/src/iconsviewsettingspage.cpp index c1b0d51c3..3f0ffb23f 100644 --- a/src/iconsviewsettingspage.cpp +++ b/src/iconsviewsettingspage.cpp @@ -1,6 +1,5 @@ /*************************************************************************** - * Copyright (C) 2006 by Peter Penz * - * peter.penz@gmx.at * + * Copyright (C) 2006 by Peter Penz * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * @@ -19,11 +18,12 @@ ***************************************************************************/ #include "iconsviewsettingspage.h" -#include "dolphin_iconsmodesettings.h" + #include "dolphinsettings.h" +#include "iconsizedialog.h" #include "pixmapviewer.h" -#include +#include "dolphin_iconsmodesettings.h" #include #include @@ -38,6 +38,7 @@ #include #include +#include #include #define GRID_SPACING_BASE 8 @@ -47,8 +48,9 @@ IconsViewSettingsPage::IconsViewSettingsPage(DolphinMainWindow* mainWindow, QWidget* parent) : KVBox(parent), m_mainWindow(mainWindow), - m_iconSizeSlider(0), - m_previewSizeSlider(0), + m_iconSize(0), + m_previewSize(0), + m_iconSizeButton(0), m_textWidthBox(0), m_fontFamilyBox(0), m_fontSizeBox(0), @@ -65,56 +67,17 @@ IconsViewSettingsPage::IconsViewSettingsPage(DolphinMainWindow* mainWindow, setMargin(margin); IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings(); - assert(settings != 0); + Q_ASSERT(settings != 0); + m_iconSize = settings->iconSize(); + m_previewSize = settings->previewSize(); KHBox* sizesLayout = new KHBox(this); sizesLayout->setSpacing(spacing); sizesLayout->setSizePolicy(sizePolicy); - // create 'Icon Size' group including slider and preview - Q3GroupBox* iconSizeGroup = new Q3GroupBox(2, Qt::Vertical, i18n("Icon Size"), sizesLayout); - iconSizeGroup->setSizePolicy(sizePolicy); - iconSizeGroup->setMargin(margin); - - const QColor iconBackgroundColor(KGlobalSettings::baseColor()); - - KHBox* iconSizeVBox = new KHBox(iconSizeGroup); - iconSizeVBox->setSpacing(spacing); - new QLabel(i18n("Small"), iconSizeVBox); - m_iconSizeSlider = new QSlider(0, 5, 1, 0, Qt::Horizontal, iconSizeVBox); - m_iconSizeSlider->setValue(sliderValue(settings->iconSize())); - m_iconSizeSlider->setTickmarks(QSlider::TicksBelow); - connect(m_iconSizeSlider, SIGNAL(valueChanged(int)), - this, SLOT(slotIconSizeChanged(int))); - new QLabel(i18n("Large"), iconSizeVBox); - - m_iconSizeViewer = new PixmapViewer(iconSizeGroup); - m_iconSizeViewer->setMinimumWidth(K3Icon::SizeEnormous); - m_iconSizeViewer->setFixedHeight(K3Icon::SizeEnormous); - m_iconSizeViewer->setEraseColor(iconBackgroundColor); - slotIconSizeChanged(m_iconSizeSlider->value()); - - // create 'Preview Size' group including slider and preview - Q3GroupBox* previewSizeGroup = new Q3GroupBox(2, Qt::Vertical, i18n("Preview Size"), sizesLayout); - previewSizeGroup->setSizePolicy(sizePolicy); - previewSizeGroup->setMargin(margin); - - KHBox* previewSizeVBox = new KHBox(previewSizeGroup); - previewSizeVBox->setSpacing(spacing); - new QLabel(i18n("Small"), previewSizeVBox); - m_previewSizeSlider = new QSlider(0, 5, 1, 0, Qt::Horizontal, previewSizeVBox); - m_previewSizeSlider->setValue(sliderValue(settings->previewSize())); - m_previewSizeSlider->setTickmarks(QSlider::TicksBelow); - connect(m_previewSizeSlider, SIGNAL(valueChanged(int)), - this, SLOT(slotPreviewSizeChanged(int))); - new QLabel(i18n("Large"), previewSizeVBox); - - m_previewSizeViewer = new PixmapViewer(previewSizeGroup); - m_previewSizeViewer->setMinimumWidth(K3Icon::SizeEnormous); - m_previewSizeViewer->setFixedHeight(K3Icon::SizeEnormous); - m_previewSizeViewer->setEraseColor(iconBackgroundColor); - - slotPreviewSizeChanged(m_previewSizeSlider->value()); + m_iconSizeButton = new QPushButton(i18n("Change icon and preview size..."), this); + connect(m_iconSizeButton, SIGNAL(clicked()), + this, SLOT(openIconSizeDialog())); Q3GroupBox* textGroup = new Q3GroupBox(2, Qt::Horizontal, i18n("Text"), this); textGroup->setSizePolicy(sizePolicy); @@ -180,17 +143,10 @@ IconsViewSettingsPage::~IconsViewSettingsPage() void IconsViewSettingsPage::applySettings() { IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings(); - assert(settings != 0); - - const int defaultSize = iconSize(m_iconSizeSlider->value()); - settings->setIconSize(defaultSize); + Q_ASSERT(settings != 0); - int previewSize = iconSize(m_previewSizeSlider->value()); - if (previewSize < defaultSize) { - // assure that the preview size is never smaller than the icon size - previewSize = defaultSize; - } - settings->setPreviewSize(previewSize); + settings->setIconSize(m_iconSize); + settings->setPreviewSize(m_previewSize); const int fontSize = m_fontSizeBox->value(); @@ -202,6 +158,7 @@ void IconsViewSettingsPage::applySettings() // TODO: this is just a very rough testing code to calculate the grid // width and height + const int defaultSize = settings->iconSize(); int gridWidth = defaultSize; int gridHeight = defaultSize; const int textSizeIndex = m_textWidthBox->currentIndex(); @@ -226,65 +183,21 @@ void IconsViewSettingsPage::applySettings() m_gridSpacingBox->currentIndex() * GRID_SPACING_INC); } -void IconsViewSettingsPage::slotIconSizeChanged(int value) +void IconsViewSettingsPage::openIconSizeDialog() { - KIconLoader iconLoader; - m_iconSizeViewer->setPixmap(iconLoader.loadIcon("folder", K3Icon::Desktop, iconSize(value))); - - if (m_previewSizeSlider != 0) { - int previewSizeValue = m_previewSizeSlider->value(); - if (previewSizeValue < value) { - // assure that the preview size is never smaller than the icon size - previewSizeValue = value; - } - slotPreviewSizeChanged(previewSizeValue); + IconSizeDialog dialog(this); + if (dialog.exec() == QDialog::Accepted) { + m_iconSize = dialog.iconSize(); + m_previewSize = dialog.previewSize(); } } -void IconsViewSettingsPage::slotPreviewSizeChanged(int value) -{ - KIconLoader iconLoader; - const int iconSizeValue = m_iconSizeSlider->value(); - if (value < iconSizeValue) { - // assure that the preview size is never smaller than the icon size - value = iconSizeValue; - } - m_previewSizeViewer->setPixmap(iconLoader.loadIcon("preview", K3Icon::Desktop, iconSize(value))); -} -int IconsViewSettingsPage::iconSize(int sliderValue) const -{ - int size = K3Icon::SizeMedium; - switch (sliderValue) { - case 0: size = K3Icon::SizeSmall; break; - case 1: size = K3Icon::SizeSmallMedium; break; - case 2: size = K3Icon::SizeMedium; break; - case 3: size = K3Icon::SizeLarge; break; - case 4: size = K3Icon::SizeHuge; break; - case 5: size = K3Icon::SizeEnormous; break; - } - return size; -} - -int IconsViewSettingsPage::sliderValue(int iconSize) const -{ - int value = 0; - switch (iconSize) { - case K3Icon::SizeSmall: value = 0; break; - case K3Icon::SizeSmallMedium: value = 1; break; - case K3Icon::SizeMedium: value = 2; break; - case K3Icon::SizeLarge: value = 3; break; - case K3Icon::SizeHuge: value = 4; break; - case K3Icon::SizeEnormous: value = 5; break; - default: break; - } - return value; -} void IconsViewSettingsPage::adjustTextWidthSelection() { IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings(); - assert(settings != 0); + Q_ASSERT(settings != 0); //m_textWidthBox->setCurrentIndex(DolphinSettings::instance().textWidthHint()); } diff --git a/src/iconsviewsettingspage.h b/src/iconsviewsettingspage.h index aa106ef27..c9f5b8a74 100644 --- a/src/iconsviewsettingspage.h +++ b/src/iconsviewsettingspage.h @@ -1,6 +1,5 @@ /*************************************************************************** - * Copyright (C) 2006 by Peter Penz * - * peter.penz@gmx.at * + * Copyright (C) 2006 by Peter Penz * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * @@ -31,7 +30,6 @@ class QCheckBox; class QPushButton; class QSpinBox; class QFontComboBox; -class PixmapViewer; /** * @brief Tab page for the 'Icons Mode' and 'Previews Mode' settings @@ -65,15 +63,21 @@ public: void applySettings(); private slots: - void slotIconSizeChanged(int value); - void slotPreviewSizeChanged(int value); + void openIconSizeDialog(); + +private: + /** + * Adjusts the selection of the text width combo box dependant + * from the grid width and grid height settings. + */ + void adjustTextWidthSelection(); private: DolphinMainWindow* m_mainWindow; - QSlider* m_iconSizeSlider; - PixmapViewer* m_iconSizeViewer; - QSlider* m_previewSizeSlider; - PixmapViewer* m_previewSizeViewer; + int m_iconSize; + int m_previewSize; + + QPushButton* m_iconSizeButton; QComboBox* m_textWidthBox; QFontComboBox* m_fontFamilyBox; QSpinBox* m_fontSizeBox; @@ -82,18 +86,6 @@ private: QComboBox* m_arrangementBox; QComboBox* m_gridSpacingBox; - - /** Returns the icon size for the given slider value. */ - int iconSize(int sliderValue) const; - - /** Returns the slider value for the given icon size. */ - int sliderValue(int iconSize) const; - - /** - * Adjusts the selection of the text width combo box dependant - * from the grid width and grid height settings. - */ - void adjustTextWidthSelection(); }; #endif diff --git a/src/infosidebarpage.h b/src/infosidebarpage.h index e60d4c3d3..ffc73bec4 100644 --- a/src/infosidebarpage.h +++ b/src/infosidebarpage.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2006 by Peter Penz + * Copyright (C) 2006 by Peter Penz * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by *