KDE/kdebase/workspace

Rafael Fernández López ereslibre at kde.org
Tue Apr 1 17:53:53 CEST 2008


SVN commit 792562 by ereslibre:

Kickoff changes asked on panel-devel. As voted, the background painting did not get in

- Strict mouse hover
    - Leaving an item will unselect that item
    - Leaving the viewport will unselect the selected item if was any
- Better keyboard navigation
    - If no item selected, Up will select the last item, Down will select the first item
- Search improvements
    - The first result becomes the selected index, if exists
    - The bottom tabbar is hidden for ease of use, intuitivity and letting more room for search results

CCMAIL: panel-devel at kde.org


 M  +1 -1      libs/plasma/delegate.cpp  
 M  +4 -0      plasma/applets/kickoff/core/searchmodel.cpp  
 M  +3 -0      plasma/applets/kickoff/core/searchmodel.h  
 M  +17 -16    plasma/applets/kickoff/ui/flipscrollview.cpp  
 M  +1 -1      plasma/applets/kickoff/ui/flipscrollview.h  
 M  +18 -4     plasma/applets/kickoff/ui/launcher.cpp  
 M  +1 -0      plasma/applets/kickoff/ui/launcher.h  
 M  +22 -16    plasma/applets/kickoff/ui/urlitemview.cpp  
 M  +1 -0      plasma/applets/kickoff/ui/urlitemview.h  


--- trunk/KDE/kdebase/workspace/libs/plasma/delegate.cpp #792561:792562
@@ -190,7 +190,7 @@
 
 void Delegate::paint(QPainter *painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
 {
-    const bool hover = option.state & (QStyle::State_Selected|QStyle::State_MouseOver|QStyle::State_HasFocus);
+    const bool hover = option.state & (QStyle::State_MouseOver | QStyle::State_Selected);
 
     QRect contentRect = option.rect;
     contentRect.setBottom(contentRect.bottom() - 1);
--- trunk/KDE/kdebase/workspace/plasma/applets/kickoff/core/searchmodel.cpp #792561:792562
@@ -74,6 +74,10 @@
                 this,SLOT(resultsAvailable(QStringList)));
         connect(iface,SIGNAL(resultsAvailable(ResultList)),
                 this,SLOT(resultsAvailable(ResultList)));
+        connect(iface,SIGNAL(resultsAvailable(QStringList)),
+                this,SIGNAL(resultsAvailable()));
+        connect(iface,SIGNAL(resultsAvailable(ResultList)),
+                this,SIGNAL(resultsAvailable()));
     }
 }
 SearchModel::~SearchModel()
--- trunk/KDE/kdebase/workspace/plasma/applets/kickoff/core/searchmodel.h #792561:792562
@@ -50,6 +50,9 @@
     void resultsAvailable(const QStringList& results);
     void resultsAvailable(const ResultList& results);
 
+Q_SIGNALS:
+    void resultsAvailable();
+
 private:
     class Private;
     Private * const d;
--- trunk/KDE/kdebase/workspace/plasma/applets/kickoff/ui/flipscrollview.cpp #792561:792562
@@ -180,8 +180,7 @@
     void drawBackArrow(QPainter *painter,QStyle::State state)
     {
         painter->save();
-        if (state & QStyle::State_MouseOver &&
-                state & QStyle::State_Enabled) {
+        if (state & QStyle::State_MouseOver) {
             painter->setBrush(q->palette().highlight());
         } else {
             painter->setBrush(q->palette().mid());
@@ -295,6 +294,7 @@
     int rowIndex = (point.y() - topOffset) / itemHeight();
 
     QRect itemRect = rect();
+    itemRect.setTop(itemRect.top() + topOffset);
     itemRect.setLeft(d->backArrowRect().right() + ItemDelegate::BACK_ARROW_SPACING);
 
     if (rowIndex < items && itemRect.contains(point)) {
@@ -411,13 +411,17 @@
    // kDebug() << "Moving cursor with current index" << index.data(Qt::DisplayRole);
     switch (cursorAction) {
         case MoveUp:
-                if (currentIndex().row() > 0) {
+                if (!currentIndex().isValid()) {
+                    index = model()->index(model()->rowCount(d->currentRoot()) - 1, 0, d->currentRoot());
+                } else if (currentIndex().row() > 0) {
                     index = currentIndex().sibling(currentIndex().row()-1,
                                                    currentIndex().column());
                 }
             break;
         case MoveDown:
-                if (currentIndex().row() <
+                if (!currentIndex().isValid()) {
+                    index = model()->index(0, 0, d->currentRoot());
+                } else if (currentIndex().row() <
                         model()->rowCount(currentIndex().parent())-1 ) {
                     index = currentIndex().sibling(currentIndex().row()+1,
                                                    currentIndex().column());
@@ -451,14 +455,6 @@
     return index;
 }
 
-void FlipScrollView::setModel(QAbstractItemModel *model)
-{
-    QAbstractItemView::setModel(model);
-    if (model) {
-        setCurrentIndex(model->index(0,0));
-    }
-}
-
 void FlipScrollView::setSelection(const QRect& rect , QItemSelectionModel::SelectionFlags flags)
 {
     QItemSelection selection;
@@ -507,7 +503,7 @@
         setDirtyRegion(d->backArrowRect());
     } else {
         const QModelIndex itemUnderMouse = indexAt(event->pos());
-        if (itemUnderMouse != d->hoveredIndex && itemUnderMouse.isValid()) {
+        if (itemUnderMouse != d->hoveredIndex) {
             update(itemUnderMouse);
             update(d->hoveredIndex);
 
@@ -538,6 +534,12 @@
     QAbstractItemView::keyPressEvent(event);
 }
 
+void FlipScrollView::leaveEvent(QEvent *event)
+{
+    d->hoveredIndex = QModelIndex();
+    setCurrentIndex(QModelIndex());
+}
+
 void FlipScrollView::paintItems(QPainter &painter, QPaintEvent *event, QModelIndex &root)
 {
     const int rows = model()->rowCount(root);
@@ -572,12 +574,11 @@
         if (model()->hasChildren(index)) {
             painter.save();
             painter.setPen(Qt::NoPen);
-
             // there is an assumption made here that the delegate will fill the background
             // with the selected color or some similar color which contrasts well with the
             // highlighted text color
-            if (option.state & (QStyle::State_Selected|QStyle::State_MouseOver)) {
-                painter.setBrush(palette().highlight());
+            if (option.state & QStyle::State_MouseOver) {
+                painter.setBrush(palette().highlightedText());
             } else {
                 painter.setBrush(palette().text());
             }
--- trunk/KDE/kdebase/workspace/plasma/applets/kickoff/ui/flipscrollview.h #792561:792562
@@ -58,7 +58,6 @@
     virtual void scrollTo(const QModelIndex& index, ScrollHint hint = EnsureVisible);
     virtual QRect visualRect(const QModelIndex& index) const;
 
-    virtual void setModel(QAbstractItemModel *model);
     int itemHeight() const;
 
 protected:
@@ -68,6 +67,7 @@
     virtual void mouseReleaseEvent(QMouseEvent *event);
     virtual void resizeEvent(QResizeEvent *event);
     virtual void keyPressEvent(QKeyEvent *event);
+    virtual void leaveEvent(QEvent *event);
 
     // reimplemented from QAbstractItemView 
     virtual bool isIndexHidden(const QModelIndex& index) const;
--- trunk/KDE/kdebase/workspace/plasma/applets/kickoff/ui/launcher.cpp #792561:792562
@@ -80,6 +80,7 @@
         , applet(0)
         , urlLauncher(new UrlItemLauncher(launcher))
         , resizeHandle(0)
+        , searchModel(0)
         , searchBar(0)
         , footer(0)
         , contentArea(0)
@@ -228,21 +229,23 @@
 
     void setupSearchView()
     {
-        SearchModel *model = new SearchModel(q);
+        searchModel = new SearchModel(q);
         UrlItemView *view = new UrlItemView;
         ItemDelegate *delegate = new ItemDelegate;
         delegate->setRole(Plasma::Delegate::SubTitleRole, SubTitleRole);
         delegate->setRole(Plasma::Delegate::SubTitleMandatoryRole, SubTitleMandatoryRole);
         view->setItemDelegate(delegate);
         view->setItemStateProvider(delegate);
-        view->setModel(model);
+        view->setModel(searchModel);
         view->setFrameStyle(QFrame::NoFrame);
         // prevent view from stealing focus from the search bar
         view->setFocusPolicy(Qt::NoFocus);
         view->setDragEnabled(true);
         setupEventHandler(view);
 
-        connect(searchBar, SIGNAL(queryChanged(QString)), model, SLOT(setQuery(QString)));
+        connect(searchModel, SIGNAL(resultsAvailable()), q, SLOT(resultsAvailable()));
+
+        connect(searchBar, SIGNAL(queryChanged(QString)), searchModel, SLOT(setQuery(QString)));
         connect(searchBar, SIGNAL(queryChanged(QString)), q, SLOT(focusSearchView(QString)));
 
         view->setContextMenuPolicy(Qt::CustomContextMenu);
@@ -410,6 +413,7 @@
     Plasma::Applet *applet;
     UrlItemLauncher *urlLauncher;
     ResizeHandle *resizeHandle;
+    SearchModel *searchModel;
     SearchBar *searchBar;
     QWidget *footer;
     QStackedWidget *contentArea;
@@ -701,7 +705,11 @@
 
 void Launcher::focusSearchView(const QString& query)
 {
-    if (!query.isEmpty()) {
+    bool queryEmpty = query.isEmpty();
+
+    d->contentSwitcher->setVisible(queryEmpty);
+
+    if (!queryEmpty) {
         d->contentArea->setCurrentWidget(d->searchView);
     } else {
         focusFavoritesView();
@@ -862,6 +870,12 @@
     KToolInvocation::invokeBrowser("http://www.kde.org/");
 }
 
+void Launcher::resultsAvailable()
+{
+    const QModelIndex root = d->searchModel->index(0, 0);
+    d->searchView->setCurrentIndex(d->searchModel->index(0, 0, root));
+}
+
 void Launcher::setLauncherOrigin( QPoint origin, Plasma::Location location )
 {
 /* 8 interesting positions for the menu to popup, depending where
--- trunk/KDE/kdebase/workspace/plasma/applets/kickoff/ui/launcher.h #792561:792562
@@ -93,6 +93,7 @@
     void showViewContextMenu(const QPoint& pos);
     void focusFavoritesView();
     void openHomepage();
+    void resultsAvailable();
 
 private:
     void init();
--- trunk/KDE/kdebase/workspace/plasma/applets/kickoff/ui/urlitemview.cpp #792561:792562
@@ -301,11 +301,6 @@
 {
     d->doLayout();
 
-    if (!d->visualOrder.contains(currentIndex())) {
-        // select the first valid index
-        setCurrentIndex(moveCursor(MoveDown,0)); 
-    }
-
     if (viewport()->isVisible()) {
         viewport()->update();
     }
@@ -376,24 +371,30 @@
 
     switch (cursorAction) {
         case MoveUp:
-                visualIndex = qMax(0,visualIndex-1); 
+                if (!currentIndex().isValid()) {
+                    const QModelIndex root = model()->index(0, 0);
+                    index = model()->index(model()->rowCount(root) - 1, 0, root);
+                } else {
+                    visualIndex = qMax(0,visualIndex-1);
+                }
             break;
         case MoveDown:
-                visualIndex = qMin(d->visualOrder.count()-1,visualIndex+1);
+                if (!currentIndex().isValid()) {
+                    const QModelIndex root = model()->index(0, 0);
+                    index = model()->index(0, 0, root);
+                } else {
+                    visualIndex = qMin(d->visualOrder.count()-1,visualIndex+1);
+                }
             break;
-        case MoveLeft:
-        case MoveRight:
-                // do nothing
-            break;
         default:
-
+                // Do nothing
             break;
     }
 
-    // when changing the current item with the keyboard, clear the mouse-over item
     d->hoveredIndex = QModelIndex();
 
-    return d->visualOrder.value(visualIndex,QModelIndex());
+    return currentIndex().isValid() ? d->visualOrder.value(visualIndex,QModelIndex())
+                                    : index;
 }
 
 void UrlItemView::setSelection(const QRect& rect,QItemSelectionModel::SelectionFlags flags)
@@ -466,8 +467,7 @@
 void UrlItemView::mouseMoveEvent(QMouseEvent *event)
 {
     const QModelIndex itemUnderMouse = indexAt(event->pos());
-    if (itemUnderMouse != d->hoveredIndex && itemUnderMouse.isValid() &&
-        state() == NoState) {
+    if (itemUnderMouse != d->hoveredIndex && state() == NoState) {
         update(itemUnderMouse);
         update(d->hoveredIndex);
 
@@ -508,6 +508,12 @@
     kDebug() << "UrlItemView drop event";
 }
 
+void UrlItemView::leaveEvent(QEvent *event)
+{
+    d->hoveredIndex = QModelIndex();
+    setCurrentIndex(QModelIndex());
+}
+
 ItemStateProvider *UrlItemView::itemStateProvider() const
 {
     return d->itemStateProvider;
--- trunk/KDE/kdebase/workspace/plasma/applets/kickoff/ui/urlitemview.h #792561:792562
@@ -58,6 +58,7 @@
     virtual void resizeEvent(QResizeEvent *event);
     virtual void mouseMoveEvent(QMouseEvent *event);
     virtual void dropEvent(QDropEvent *event);
+    virtual void leaveEvent(QEvent *event);
 
 private Q_SLOTS:
     // lays out all items in the view and sets the current index to the first


More information about the Panel-devel mailing list