[Digikam-devel] [Patch] make UI more usable on small screens

Matthias Welwarsky matze at welwarsky.de
Thu Feb 10 17:21:40 GMT 2011


Hi,

what do you think about the following changes to make UI more usable on small 
screens:

     - SideBarWidget is now a QScrollArea
     - minimumSizeHint() enforces minimum width of 20% of screen width, 
regardless of minimum sizes of managed widgets
     - adjust left sidebar widgets to play nice with QScrollArea

diff --git a/digikam/leftsidebarwidgets.cpp b/digikam/leftsidebarwidgets.cpp
index 6a27fe1..8cdcd68 100644
--- a/digikam/leftsidebarwidgets.cpp
+++ b/digikam/leftsidebarwidgets.cpp
@@ -87,20 +87,24 @@ 
AlbumFolderViewSideBarWidget::AlbumFolderViewSideBarWidget(QWidget* parent, 
Albu
 
     d->albumModificationHelper = albumModificationHelper;
 
-    QVBoxLayout* layout = new QVBoxLayout(this);
+    QWidget *mainWidget = new QWidget(this);
+    QVBoxLayout* layout = new QVBoxLayout(mainWidget);
 
-    d->albumFolderView = new AlbumSelectionTreeView(this, model, d-
>albumModificationHelper);
+    d->albumFolderView = new AlbumSelectionTreeView(mainWidget, model, d-
>albumModificationHelper);
     d->albumFolderView->setObjectName("AlbumFolderView");
     d->albumFolderView->setConfigGroup(getConfigGroup());
     d->albumFolderView->setExpandNewCurrentItem(true);
     d->albumFolderView->setAlbumManagerCurrentAlbum(true);
-    d->searchTextBar   = new SearchTextBar(this, 
"DigikamViewFolderSearchBar");
+    d->searchTextBar   = new SearchTextBar(mainWidget, 
"DigikamViewFolderSearchBar");
     d->searchTextBar->setHighlightOnResult(true);
     d->searchTextBar->setModel(model, AbstractAlbumModel::AlbumIdRole, 
AbstractAlbumModel::AlbumTitleRole);
     d->searchTextBar->setFilterModel(d->albumFolderView->albumFilterModel());
 
     layout->addWidget(d->albumFolderView);
     layout->addWidget(d->searchTextBar);
+    
+    setWidget(mainWidget);
+    setWidgetResizable(true);
 
     // setup connection
     connect(d->albumFolderView, SIGNAL(signalFindDuplicatesInAlbum(Album*)),
@@ -187,19 +191,23 @@ TagViewSideBarWidget::TagViewSideBarWidget(QWidget* 
parent, TagModel* model)
 
     d->tagModel = model;
 
-    QVBoxLayout* layout = new QVBoxLayout(this);
+    QWidget *mainWidget = new QWidget(this);
+    QVBoxLayout* layout = new QVBoxLayout(mainWidget);
 
-    d->tagFolderView = new TagFolderView(this, model);
+    d->tagFolderView = new TagFolderView(mainWidget, model);
     d->tagFolderView->setConfigGroup(getConfigGroup());
     d->tagFolderView->setExpandNewCurrentItem(true);
     d->tagFolderView->setAlbumManagerCurrentAlbum(true);
-    d->tagSearchBar  = new SearchTextBar(this, "DigikamViewTagSearchBar");
+    d->tagSearchBar  = new SearchTextBar(mainWidget, 
"DigikamViewTagSearchBar");
     d->tagSearchBar->setHighlightOnResult(true);
     d->tagSearchBar->setModel(model, AbstractAlbumModel::AlbumIdRole, 
AbstractAlbumModel::AlbumTitleRole);
     d->tagSearchBar->setFilterModel(d->tagFolderView->albumFilterModel());
 
     layout->addWidget(d->tagFolderView);
     layout->addWidget(d->tagSearchBar);
+    
+    setWidget(mainWidget);
+    setWidgetResizable(true);
 
     connect(d->tagFolderView, SIGNAL(signalFindDuplicatesInAlbum(Album*)),
             this, SIGNAL(signalFindDuplicatesInAlbum(Album*)));
@@ -284,6 +292,9 @@ 
DateFolderViewSideBarWidget::DateFolderViewSideBarWidget(QWidget* parent, 
DateAl
     d->dateFolderView->setImageModel(imageFilterModel);
 
     layout->addWidget(d->dateFolderView);
+    
+    setWidget(d->dateFolderView);
+    setWidgetResizable(true);
 }
 
 DateFolderViewSideBarWidget::~DateFolderViewSideBarWidget()
@@ -396,9 +407,11 @@ TimelineSideBarWidget::TimelineSideBarWidget(QWidget* 
parent, SearchModel* searc
     d->searchModificationHelper = searchModificationHelper;
     d->timer                    = new QTimer(this);
     setAttribute(Qt::WA_DeleteOnClose);
-
-    QVBoxLayout* vlay = new QVBoxLayout(this);
-    QFrame* panel     = new QFrame(this);
+    
+    QWidget* mainWidget = new QWidget(this);
+    
+    QVBoxLayout* vlay = new QVBoxLayout(mainWidget);
+    QFrame* panel     = new QFrame(mainWidget);
     panel->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
     panel->setLineWidth(1);
 
@@ -521,6 +534,9 @@ TimelineSideBarWidget::TimelineSideBarWidget(QWidget* 
parent, SearchModel* searc
     vlay->setMargin(0);
     vlay->setSpacing(0);
 
+    setWidget(mainWidget);
+    setWidgetResizable(true);
+    
     // ---------------------------------------------------------------
 
     connect(AlbumManager::instance(), SIGNAL(signalDatesMapDirty(const 
QMap<QDateTime, int>&)),
@@ -819,16 +835,17 @@ SearchSideBarWidget::SearchSideBarWidget(QWidget* 
parent, SearchModel* searchMod
 
     d->searchModel      = searchModel;
 
-    QVBoxLayout* layout = new QVBoxLayout(this);
+    QWidget *mainWidget = new QWidget(this);
+    QVBoxLayout* layout = new QVBoxLayout(mainWidget);
 
-    d->searchTabHeader  = new SearchTabHeader(this);
-    d->searchTreeView   = new NormalSearchTreeView(this, searchModel,
+    d->searchTabHeader  = new SearchTabHeader(mainWidget);
+    d->searchTreeView   = new NormalSearchTreeView(mainWidget, searchModel,
             searchModeificationHelper);
     d->searchTreeView->setConfigGroup(getConfigGroup());
     d->searchTreeView->filteredModel()->listNormalSearches();
     d->searchTreeView->filteredModel()->setListTemporarySearches(true);
     d->searchTreeView->setAlbumManagerCurrentAlbum(true);
-    d->searchSearchBar  = new SearchTextBar(this, 
"DigikamViewSearchSearchBar");
+    d->searchSearchBar  = new SearchTextBar(mainWidget, 
"DigikamViewSearchSearchBar");
     d->searchSearchBar->setModel(d->searchTreeView->filteredModel(),
                                  AbstractAlbumModel::AlbumIdRole, 
AbstractAlbumModel::AlbumTitleRole);
     d->searchSearchBar->setFilterModel(d->searchTreeView-
>albumFilterModel());
@@ -837,6 +854,9 @@ SearchSideBarWidget::SearchSideBarWidget(QWidget* parent, 
SearchModel* searchMod
     layout->addWidget(d->searchTreeView);
     layout->setStretchFactor(d->searchTreeView, 1);
     layout->addWidget(d->searchSearchBar);
+    
+    setWidget(mainWidget);
+    setWidgetResizable(true);
 
     connect(d->searchTreeView, SIGNAL(newSearch()),
             d->searchTabHeader, SLOT(newAdvancedSearch()));
@@ -935,6 +955,9 @@ 
FuzzySearchSideBarWidget::FuzzySearchSideBarWidget(QWidget* parent, 
SearchModel*
 
     layout->addWidget(d->fuzzySearchView);
 
+    setWidget(d->fuzzySearchView->mainWidget());
+    setWidgetResizable(true);
+
     connect(d->fuzzySearchView, SIGNAL(signalUpdateFingerPrints()),
             this, SIGNAL(signalUpdateFingerPrints()));
 
@@ -1032,7 +1055,10 @@ GPSSearchSideBarWidget::GPSSearchSideBarWidget(QWidget* 
parent, SearchModel* sea
     QVBoxLayout* layout = new QVBoxLayout(this);
 
     layout->addWidget(d->gpsSearchView);
-
+    
+    setWidget(d->gpsSearchView);
+    setWidgetResizable(true);
+    
     connect(d->gpsSearchView, SIGNAL(signalMapSoloItems(const 
QList<qlonglong>&, const QString&)),
             this, SIGNAL(signalMapSoloItems(const QList<qlonglong>&, const 
QString&)));
 }
@@ -1106,10 +1132,11 @@ PeopleSideBarWidget::PeopleSideBarWidget(QWidget* 
parent, TagModel* model,
     d->tagModel = model;
     d->searchModificationHelper = searchModificationHelper;
 
-    QVBoxLayout* layout = new QVBoxLayout;
+    QWidget *mainWidget = new QWidget(this);
+    QVBoxLayout* layout = new QVBoxLayout(mainWidget);
     QHBoxLayout* hlay = new QHBoxLayout;
 
-    d->tagFolderView = new TagFolderView(this, model);
+    d->tagFolderView = new TagFolderView(mainWidget, model);
     d->tagFolderView->setConfigGroup(getConfigGroup());
     d->tagFolderView->setExpandNewCurrentItem(true);
     d->tagFolderView->setAlbumManagerCurrentAlbum(true);
@@ -1117,7 +1144,7 @@ PeopleSideBarWidget::PeopleSideBarWidget(QWidget* 
parent, TagModel* model,
     d->tagFolderView->filteredModel()->listOnlyTagsWithProperty("person");
     d->tagFolderView->filteredModel()-
>setFilterBehavior(AlbumFilterModel::StrictFiltering);
 
-    d->tagSearchBar  = new SearchTextBar(this, "DigikamViewPeopleSearchBar");
+    d->tagSearchBar  = new SearchTextBar(mainWidget, 
"DigikamViewPeopleSearchBar");
     d->tagSearchBar->setHighlightOnResult(true);
     d->tagSearchBar->setModel(d->tagFolderView->filteredModel(),
                               AbstractAlbumModel::AlbumIdRole, 
AbstractAlbumModel::AlbumTitleRole);
@@ -1142,7 +1169,8 @@ PeopleSideBarWidget::PeopleSideBarWidget(QWidget* 
parent, TagModel* model,
     layout->addWidget(d->tagFolderView);
     layout->addWidget(d->tagSearchBar);
 
-    setLayout(layout);
+    setWidget(mainWidget);
+    setWidgetResizable(true);
 
     connect(d->tagFolderView, SIGNAL(signalFindDuplicatesInAlbum(Album*)),
             this, SIGNAL(signalFindDuplicatesInAlbum(Album*)));
diff --git a/digikam/sidebarwidget.cpp b/digikam/sidebarwidget.cpp
index cd6b329..065f0e8 100644
--- a/digikam/sidebarwidget.cpp
+++ b/digikam/sidebarwidget.cpp
@@ -21,13 +21,19 @@
  *
  * ============================================================ */
 
+// Qt includes
+#include <QScrollBar>
+
+// KDE includes
+#include <kglobalsettings.h>
+
 #include "sidebarwidget.moc"
 
 namespace Digikam
 {
 
 SidebarWidget::SidebarWidget(QWidget* parent) :
-    QWidget(parent), StateSavingObject(this)
+    QScrollArea(parent), StateSavingObject(this)
 {
 }
 
@@ -35,4 +41,20 @@ SidebarWidget::~SidebarWidget()
 {
 }
 
+QSize SidebarWidget::minimumSizeHint() const
+{
+    // Set scroll area to a horizontal minimum size sufficient for the 
widgets.
+    // Do not touch vertical size hint.
+    // Limit to 20% of the desktop width.
+    const QWidget *w = widget();
+    if (0 == w)
+	return QScrollArea::minimumSizeHint();
+    
+    QSize hint        = w->minimumSizeHint();
+    QRect desktopRect = KGlobalSettings::desktopGeometry(w);
+    int wSB           = verticalScrollBar()->height();
+    hint.setWidth(qMin(w->minimumSizeHint().width() + wSB, 
desktopRect.width() / 5 ));
+    return hint;
+}
+
 }
diff --git a/digikam/sidebarwidget.h b/digikam/sidebarwidget.h
index 4b9ddd0..a0c119a 100644
--- a/digikam/sidebarwidget.h
+++ b/digikam/sidebarwidget.h
@@ -28,6 +28,7 @@
 
 #include <qpixmap.h>
 #include <qwidget.h>
+#include <qscrollarea.h>
 
 // KDE includes
 
@@ -48,7 +49,7 @@ namespace Digikam
  *
  * @author jwienke
  */
-class SidebarWidget: public QWidget, public StateSavingObject
+class SidebarWidget: public QScrollArea, public StateSavingObject
 {
     Q_OBJECT
 public:
@@ -99,6 +100,11 @@ public:
      * @return localized title string
      */
     virtual QString getCaption() = 0;
+    
+    /**
+     * Reimplemented to provide a sensible size hint towards the container
+     */
+    virtual QSize minimumSizeHint() const;
 
 Q_SIGNALS:
 
diff --git a/utilities/fuzzysearch/fuzzysearchview.cpp 
b/utilities/fuzzysearch/fuzzysearchview.cpp
index 28c0168..ad163ba 100644
--- a/utilities/fuzzysearch/fuzzysearchview.cpp
+++ b/utilities/fuzzysearch/fuzzysearchview.cpp
@@ -122,7 +122,8 @@ public:
         imageSAlbum(0),
         sketchSAlbum(0),
         searchModel(0),
-        searchModificationHelper(0)
+        searchModificationHelper(0),
+        mainWidget(0)
     {
     }
 
@@ -185,6 +186,8 @@ public:
 
     SearchModel*              searchModel;
     SearchModificationHelper* searchModificationHelper;
+    
+    QWidget*                  mainWidget;
 };
 const QString 
FuzzySearchView::FuzzySearchViewPriv::configTabEntry("FuzzySearch Tab");
 const QString 
FuzzySearchView::FuzzySearchViewPriv::configPenSketchSizeEntry("Pen Sketch 
Size");
@@ -199,7 +202,7 @@ const QString 
FuzzySearchView::FuzzySearchViewPriv::configSimilarsThresholdEntry
 FuzzySearchView::FuzzySearchView(SearchModel* searchModel,
                                  SearchModificationHelper* 
searchModificationHelper,
                                  QWidget* parent)
-    : QScrollArea(parent), StateSavingObject(this),
+    : QWidget(parent), StateSavingObject(this),
       d(new FuzzySearchViewPriv)
 {
     d->thumbLoadThread = ThumbnailLoadThread::defaultThread();
@@ -207,10 +210,8 @@ FuzzySearchView::FuzzySearchView(SearchModel* 
searchModel,
     d->searchModel = searchModel;
     d->searchModificationHelper = searchModificationHelper;
 
-    setWidgetResizable(true);
     setAttribute(Qt::WA_DeleteOnClose);
     setAcceptDrops(true);
-    viewport()->setAcceptDrops(true);
 
     // ---------------------------------------------------------------
 
@@ -240,18 +241,16 @@ FuzzySearchView::FuzzySearchView(SearchModel* 
searchModel,
 
     // ---------------------------------------------------------------
 
-    QWidget* mainWidget     = new QWidget(this);
+    d->mainWidget     = new QWidget(this);
     QVBoxLayout* mainLayout = new QVBoxLayout();
     mainLayout->addWidget(d->tabWidget);
     mainLayout->addWidget(d->folderView);
     mainLayout->setMargin(0);
     mainLayout->setSpacing(0);
-    mainWidget->setLayout(mainLayout);
+    d->mainWidget->setLayout(mainLayout);
 
-    setWidget(mainWidget);
     setAutoFillBackground(false);
-    mainWidget->setAutoFillBackground(false);
-    viewport()->setAutoFillBackground(false);
+    d->mainWidget->setAutoFillBackground(false);
 
     // ---------------------------------------------------------------
 
@@ -263,6 +262,11 @@ FuzzySearchView::FuzzySearchView(SearchModel* 
searchModel,
     slotCheckNameEditImageConditions();
 }
 
+QWidget* FuzzySearchView::mainWidget() const
+{
+	return d->mainWidget;
+}
+
 QWidget* FuzzySearchView::setupFindSimilarPanel()
 {
     KHBox* imageBox     = new KHBox();
diff --git a/utilities/fuzzysearch/fuzzysearchview.h 
b/utilities/fuzzysearch/fuzzysearchview.h
index 542d8c4..7cca7fe 100644
--- a/utilities/fuzzysearch/fuzzysearchview.h
+++ b/utilities/fuzzysearch/fuzzysearchview.h
@@ -49,7 +49,7 @@ class SearchModel;
 class SearchModificationHelper;
 class SearchTextBar;
 
-class FuzzySearchView : public QScrollArea, public StateSavingObject
+class FuzzySearchView : public QWidget, public StateSavingObject
 {
     Q_OBJECT
 
@@ -71,6 +71,8 @@ public:
     virtual void setConfigGroup(KConfigGroup group);
     void doLoadState();
     void doSaveState();
+    
+    QWidget* mainWidget() const;
 
 Q_SIGNALS:
 




More information about the Digikam-devel mailing list