[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    KDirSelectDialog change icon size feature...
From:       Shaun Reich <predator106 () gmail ! com>
Date:       2009-03-14 19:02:40
Message-ID: 2165e9910903141202h4faddd82ua2bb2d983e3c376f () mail ! gmail ! com
[Download RAW message or body]

Hello, this is a patch that I need to get some feedback on, it is for
kdelibs/kfile/kdirselectdialog.cpp & .h.

I have a question, also...

Why, in the open file dialog, do the zoom in and zoom out actions on
the toolbar, they have their text set to "Zoom In" and "Zoom Out", but
it is not shown.

So it looks like the intention was to have the text there, but I do
not know why it is not. I am referring most directly to
kfilewidget.cpp. So I am not sure if it does not use that (I thought
it did), or if it is a bug, or if it is a mistake that the text should
be nil.

I added this feature because you can set the icon size in the open
file dialog and I want it to be a feature in this folder dialog.
Mostly, due in part because I do not like the default icon size, and
like to be able to change it to whatever I want.

Ignore the qDebug(), it won't be a part of it...

What do you guys think? It may be kind of sloppy still, not sure...

--
Riverenter Vestri,
Shaun Reich

["kdirselectdialog.cpp.diff" (text/x-patch)]

--- shaun/.kde4/tmp/kde-shaun/kdirselectdialog.cpp-BASEC24986.tmp	2009-03-14 14:41:20.000000000 -0400
+++ kde-devel/kde/src/kdelibs/kfile/kdirselectdialog.cpp	2009-03-14 14:36:22.000000000 -0400
@@ -23,6 +23,7 @@
 #include <QtCore/QDir>
 #include <QtCore/QStringList>
 #include <QtGui/QLayout>
+#include <QtGui/QHelpEvent>
 
 #include <kactioncollection.h>
 #include <kapplication.h>
@@ -52,6 +53,7 @@
 #include <kpropertiesdialog.h>
 #include <kpushbutton.h>
 #include <kmenu.h>
+#include <ktoolbar.h>
 
 #include "kfileplacesview.h"
 #include "kfileplacesmodel.h"
@@ -83,6 +85,9 @@ public:
     void slotMoveToTrash();
     void slotDelete();
     void slotProperties();
+    void slotIconSizeChanged(int iconSize);
+    void slotZoomIn();
+    void slotZoomOut();
 
     KDirSelectDialog *m_parent;
     bool m_localOnly : 1;
@@ -98,6 +103,8 @@ public:
     KUrl m_startURL;
     KAction* moveToTrash;
     KAction* deleteAction;
+    QSlider* iconSizeSlider;
+    KToolBar* toolBar;
 };
 
 void KDirSelectDialog::Private::readConfig(const KSharedConfig::Ptr &config, const QString& group)
@@ -252,6 +259,45 @@ void KDirSelectDialog::Private::slotProp
     dialog->show();
 }
 
+void KDirSelectDialog::Private::slotIconSizeChanged(int iconSize)
+{
+    int maxSize = KIconLoader::SizeEnormous - KIconLoader::SizeSmall;
+    int value = (maxSize * iconSize / 100) + KIconLoader::SizeSmall;
+    switch (value) {
+        case KIconLoader::SizeSmall:
+        case KIconLoader::SizeSmallMedium:
+        case KIconLoader::SizeMedium:
+        case KIconLoader::SizeLarge:
+        case KIconLoader::SizeHuge:
+        case KIconLoader::SizeEnormous:
+            iconSizeSlider->setToolTip(i18n("Icon size: %1 pixels (standard size)", value));
+            break;
+        default:
+            iconSizeSlider->setToolTip(i18n("Icon size: %1 pixels", value));
+            break;
+    }
+
+    QPoint global(iconSizeSlider->rect().topLeft());
+    global.ry() += iconSizeSlider->height() / 2;
+    QHelpEvent toolTipEvent(QEvent::ToolTip, QPoint(0, 0), iconSizeSlider->mapToGlobal(global));
+    QApplication::sendEvent(iconSizeSlider, &toolTipEvent);
+    m_treeView->setIconSize(QSize(value, value));
+}
+
+void KDirSelectDialog::Private::slotZoomIn()
+{
+    const int currValue = iconSizeSlider->value();
+    const int futValue = qMin(100, currValue + 10);
+    iconSizeSlider->setValue(futValue);
+}
+
+void KDirSelectDialog::Private::slotZoomOut()
+{
+     const int currValue = iconSizeSlider->value();
+    const int futValue = qMax(0, currValue - 10);
+    iconSizeSlider->setValue(futValue);
+}
+
 
 KDirSelectDialog::KDirSelectDialog(const KUrl &startDir, bool localOnly,
                                    QWidget *parent)
@@ -275,6 +321,28 @@ KDirSelectDialog::KDirSelectDialog(const
     hlay->setMargin(0);
     hlay->setSpacing(spacingHint());
     QVBoxLayout *mainLayout = new QVBoxLayout();
+
+    d->iconSizeSlider = new QSlider(this);
+    d->iconSizeSlider->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Fixed);
+    d->iconSizeSlider->setOrientation(Qt::Horizontal);
+    d->iconSizeSlider->setMinimum(0);
+    d->iconSizeSlider->setMaximum(100);
+    d->iconSizeSlider->installEventFilter(this);
+
+    KAction *zoomOut = new KAction(KIcon("zoom-out"), i18n("Zoom out"), this);
+    connect(zoomOut, SIGNAL(triggered()), SLOT(slotZoomOut()));
+    KAction *zoomIn = new KAction(KIcon("zoom-in"), i18n("Zoom in"), this);
+    connect(zoomIn, SIGNAL(triggered()), SLOT(slotZoomIn()));
+
+    d->toolBar = new KToolBar(this, true);
+    mainLayout->addWidget(d->toolBar, 0, Qt::AlignRight);
+    d->toolBar->addAction(zoomOut);
+    d->toolBar->addWidget(d->iconSizeSlider);
+    d->toolBar->addAction(zoomIn);
+
+   connect(d->iconSizeSlider, SIGNAL(valueChanged(int)),
+           this, SLOT(slotIconSizeChanged(int)));
+
     d->m_actions=new KActionCollection(this);
     d->m_placesView = new KFilePlacesView( page );
     d->m_placesView->setModel(new KFilePlacesModel(d->m_placesView));

["kdirselectdialog.h.diff" (text/x-patch)]

--- shaun/.kde4/tmp/kde-shaun/kdirselectdialog.h-BASEZ24986.tmp	2009-03-14 14:46:00.000000000 -0400
+++ kde-devel/kde/src/kdelibs/kfile/kdirselectdialog.h	2009-03-14 13:29:58.000000000 -0400
@@ -120,6 +120,9 @@ private:
     Q_PRIVATE_SLOT( d, void slotMoveToTrash() )
     Q_PRIVATE_SLOT( d, void slotDelete() )
     Q_PRIVATE_SLOT( d, void slotProperties() )
+    Q_PRIVATE_SLOT( d, void slotIconSizeChanged(int))
+    Q_PRIVATE_SLOT( d, void slotZoomIn())
+    Q_PRIVATE_SLOT( d, void slotZoomOut())
 };
 
 #endif


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic