]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphiniconsview.cpp
Get back names, and use "using" keyword to keep GCC silent on "method foo on base...
[dolphin.git] / src / dolphiniconsview.cpp
index a8188d9717e09fc0264df175cf2c164f0a775440..46c27cd28f6cb0f78036b2e9fa5e94bf52e6d53d 100644 (file)
@@ -43,7 +43,7 @@ DolphinIconsView::DolphinIconsView(QWidget* parent,
                                    DolphinSortFilterProxyModel* proxyModel) :
     KCategorizedView(parent),
     m_controller(controller),
-    m_categoryDrawer(0),
+    m_categoryDrawer(new DolphinCategoryDrawer(this)),
     m_extensionsFactory(0),
     m_font(),
     m_decorationSize(),
@@ -95,9 +95,10 @@ DolphinIconsView::DolphinIconsView(QWidget* parent,
         m_font = KGlobalSettings::generalFont();
     } else {
         m_font = QFont(settings->fontFamily(),
-                       settings->fontSize(),
+                       qRound(settings->fontSize()),
                        settings->fontWeight(),
                        settings->italicFont());
+        m_font.setPointSizeF(settings->fontSize());
     }
 
     setWordWrap(settings->numberOfTextlines() > 1);
@@ -112,7 +113,7 @@ DolphinIconsView::DolphinIconsView(QWidget* parent,
         m_displayAlignment = Qt::AlignLeft | Qt::AlignVCenter;
     }
 
-    m_categoryDrawer = new DolphinCategoryDrawer();
+    connect(m_categoryDrawer, SIGNAL(actionRequested(int,QModelIndex)), this, SLOT(categoryDrawerActionRequested(int,QModelIndex)));
     setCategoryDrawer(m_categoryDrawer);
 
     setFocus();
@@ -126,8 +127,6 @@ DolphinIconsView::DolphinIconsView(QWidget* parent,
 
 DolphinIconsView::~DolphinIconsView()
 {
-    delete m_categoryDrawer;
-    m_categoryDrawer = 0;
 }
 
 void DolphinIconsView::dataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight)
@@ -173,14 +172,8 @@ void DolphinIconsView::mousePressEvent(QMouseEvent* event)
         setState(QAbstractItemView::DraggingState);
     }
 
-    if (!index.isValid()) {
-        if (QApplication::mouseButtons() & Qt::MidButton) {
-            m_controller->replaceUrlByClipboard();
-        }
-        const Qt::KeyboardModifiers modifier = QApplication::keyboardModifiers();
-        if (!(modifier & Qt::ShiftModifier) && !(modifier & Qt::ControlModifier)) {
-            clearSelection();
-        }
+    if (!index.isValid() && (QApplication::mouseButtons() & Qt::MidButton)) {
+         m_controller->replaceUrlByClipboard();
     }
 
     KCategorizedView::mousePressEvent(event);
@@ -429,6 +422,33 @@ void DolphinIconsView::slotGlobalSettingsChanged(int category)
     }
 }
 
+void DolphinIconsView::categoryDrawerActionRequested(int action, const QModelIndex &index)
+{
+    const QSortFilterProxyModel *model = dynamic_cast<const QSortFilterProxyModel*>(index.model());
+    const QModelIndex topLeft = model->index(index.row(), modelColumn());
+    QModelIndex bottomRight = topLeft;
+    const QString category = model->data(index, KCategorizedSortFilterProxyModel::CategoryDisplayRole).toString();
+    QModelIndex current = topLeft;
+    while (true) {
+        current = model->index(current.row() + 1, modelColumn());
+        const QString curCategory = model->data(model->index(current.row(), index.column()), KCategorizedSortFilterProxyModel::CategoryDisplayRole).toString();
+        if (!current.isValid() || category != curCategory) {
+            break;
+        }
+        bottomRight = current;
+    }
+    switch (action) {
+        case DolphinCategoryDrawer::SelectAll:
+            selectionModel()->select(QItemSelection(topLeft, bottomRight), QItemSelectionModel::Select);
+            break;
+        case DolphinCategoryDrawer::UnselectAll:
+            selectionModel()->select(QItemSelection(topLeft, bottomRight), QItemSelectionModel::Deselect);
+            break;
+        default:
+            break;
+    }
+}
+
 void DolphinIconsView::updateGridSize(bool showPreview, int additionalInfoCount)
 {
     const IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings();
@@ -448,7 +468,7 @@ void DolphinIconsView::updateGridSize(bool showPreview, int additionalInfoCount)
     }
 
     Q_ASSERT(additionalInfoCount >= 0);
-    itemHeight += additionalInfoCount * m_font.pointSize() * 2;
+    itemHeight += additionalInfoCount * QFontMetrics(m_font).height();
 
     // Optimize the item size of the grid in a way to prevent large gaps on the
     // right border (= row arrangement) or the bottom border (= column arrangement).