Author: kmachalkova Date: Thu Jun 18 17:26:32 2009 New Revision: 57642 URL: http://svn.opensuse.org/viewcvs/yast?rev=57642&view=rev Log: Highlight selected category header after selecting category from the left panel Modified: branches/tmp/tgoettlicher/yast2cc_rewrite/src/kcategorizedview.cpp branches/tmp/tgoettlicher/yast2cc_rewrite/src/kcategorizedview.h branches/tmp/tgoettlicher/yast2cc_rewrite/src/kcategorizedview_p.h branches/tmp/tgoettlicher/yast2cc_rewrite/src/kcategorydrawer.cpp branches/tmp/tgoettlicher/yast2cc_rewrite/src/kcategorydrawer.h branches/tmp/tgoettlicher/yast2cc_rewrite/src/main_window.cpp Modified: branches/tmp/tgoettlicher/yast2cc_rewrite/src/kcategorizedview.cpp URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/tgoettlicher/yast2cc_rewri... ============================================================================== --- branches/tmp/tgoettlicher/yast2cc_rewrite/src/kcategorizedview.cpp (original) +++ branches/tmp/tgoettlicher/yast2cc_rewrite/src/kcategorizedview.cpp Thu Jun 18 17:26:32 2009 @@ -26,6 +26,7 @@ #include <QPainter> #include <QScrollBar> #include <QPaintEvent> +#include <QDebug> #include "kcategorydrawer.h" @@ -401,10 +402,11 @@ return; } + QStyleOption optionCopy = option; const QString category = proxyModel->data(index, KCategorizedSortFilterProxyModel::CategoryDisplayRole).toString(); - optionCopy.state &= ~QStyle::State_Selected; + //optionCopy.state &= ~QStyle::State_Selected; if ((listView->selectionMode() != SingleSelection) && (listView->selectionMode() != NoSelection)) { if ((category == hoveredCategory) && !mouseButtonPressed) @@ -680,6 +682,16 @@ } } +void KCategorizedView::selectCategory( const QString cat ) +{ + QRect previous = d->categoryVisualRect( d->selectedCategory ); + d->selectedCategory = cat; + QRect current = d->categoryVisualRect( d->selectedCategory ); + + viewport()->update( previous ); + viewport()->update( current ); +} + QModelIndex KCategorizedView::indexAt(const QPoint &point) const { if (!d->proxyModel || !d->categoryDrawer || !d->proxyModel->isCategorizedModel()) @@ -809,12 +821,17 @@ otherOption.rect = d->categoryVisualRect(category); otherOption.state &= ~QStyle::State_MouseOver; + if (category == d->selectedCategory) + otherOption.state |= QStyle::State_Selected; + else + otherOption.state &= ~QStyle::State_Selected; + if (otherOption.rect.intersects(area)) { intersectedInThePast = true; + QModelIndex indexToDraw = d->proxyModel->index(d->categoriesIndexes[category][0].row(), d->proxyModel->sortColumn()); - d->drawNewCategory(indexToDraw, d->proxyModel->sortRole(), otherOption, &painter); } Modified: branches/tmp/tgoettlicher/yast2cc_rewrite/src/kcategorizedview.h URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/tgoettlicher/yast2cc_rewri... ============================================================================== --- branches/tmp/tgoettlicher/yast2cc_rewrite/src/kcategorizedview.h (original) +++ branches/tmp/tgoettlicher/yast2cc_rewrite/src/kcategorizedview.h Thu Jun 18 17:26:32 2009 @@ -58,6 +58,8 @@ void setCategoryDrawer(KCategoryDrawer *categoryDrawer); + void selectCategory ( const QString cat ); + virtual QModelIndex indexAt(const QPoint &point) const; public Q_SLOTS: Modified: branches/tmp/tgoettlicher/yast2cc_rewrite/src/kcategorizedview_p.h URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/tgoettlicher/yast2cc_rewri... ============================================================================== --- branches/tmp/tgoettlicher/yast2cc_rewrite/src/kcategorizedview_p.h (original) +++ branches/tmp/tgoettlicher/yast2cc_rewrite/src/kcategorizedview_p.h Thu Jun 18 17:26:32 2009 @@ -135,6 +135,7 @@ bool dragLeftViewport; QModelIndex hovered; QString hoveredCategory; + QString selectedCategory; QPoint initialPressPosition; QPoint mousePosition; int forcedSelectionPosition; Modified: branches/tmp/tgoettlicher/yast2cc_rewrite/src/kcategorydrawer.cpp URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/tgoettlicher/yast2cc_rewri... ============================================================================== --- branches/tmp/tgoettlicher/yast2cc_rewrite/src/kcategorydrawer.cpp (original) +++ branches/tmp/tgoettlicher/yast2cc_rewrite/src/kcategorydrawer.cpp Thu Jun 18 17:26:32 2009 @@ -23,6 +23,7 @@ #include <QPainter> #include <QStyleOption> #include <QApplication> +#include <QDebug> #define HORIZONTAL_HINT 3 @@ -43,17 +44,20 @@ QColor color; + painter->save(); + painter->setRenderHint(QPainter::Antialiasing); + if (option.state & QStyle::State_Selected) { color = option.palette.color(QPalette::HighlightedText); + QColor bgcolor = option.palette.color(QPalette::Highlight); + painter->fillRect(option.rect, linearG( option, bgcolor )); } else { color = option.palette.color(QPalette::Text); } - painter->save(); - painter->setRenderHint(QPainter::Antialiasing); QStyleOptionViewItemV4 viewOptions; viewOptions.rect = option.rect; @@ -68,19 +72,14 @@ QFontMetrics metrics(painterFont); painter->setFont(painterFont); + QRect lineRect(option.rect.left(), option.rect.bottom() - 1, option.rect.width(), 1); - QLinearGradient gradient(option.rect.topLeft(), - option.rect.bottomRight()); - gradient.setColorAt(option.direction == Qt::LeftToRight ? 0 - : 1, color); - gradient.setColorAt(option.direction == Qt::LeftToRight ? 1 - : 0, Qt::transparent); - painter->fillRect(lineRect, gradient); + painter->fillRect(lineRect, linearG( option, color )); painter->setPen(color); @@ -99,3 +98,17 @@ return option.fontMetrics.height() + 4 /* 3 separator; 1 gradient */; } + +QLinearGradient KCategoryDrawer::linearG ( const QStyleOption &option, const QColor col ) const +{ + + QLinearGradient gradient = QLinearGradient(option.rect.topLeft(), + option.rect.bottomRight()); + + gradient.setColorAt(option.direction == Qt::LeftToRight ? 0 + : 1, col); + gradient.setColorAt(option.direction == Qt::LeftToRight ? 1 + : 0, Qt::transparent); + + return gradient; +} Modified: branches/tmp/tgoettlicher/yast2cc_rewrite/src/kcategorydrawer.h URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/tgoettlicher/yast2cc_rewri... ============================================================================== --- branches/tmp/tgoettlicher/yast2cc_rewrite/src/kcategorydrawer.h (original) +++ branches/tmp/tgoettlicher/yast2cc_rewrite/src/kcategorydrawer.h Thu Jun 18 17:26:32 2009 @@ -25,6 +25,7 @@ #define KDEUI_EXPORT class QPainter; +class QLinearGradient; class QModelIndex; class QStyleOption; @@ -48,6 +49,8 @@ QPainter *painter) const; virtual int categoryHeight(const QModelIndex &index, const QStyleOption &option) const; + + QLinearGradient linearG( const QStyleOption &option, const QColor col ) const; }; #endif // KCATEGORYDRAWER_H Modified: branches/tmp/tgoettlicher/yast2cc_rewrite/src/main_window.cpp URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/tgoettlicher/yast2cc_rewri... ============================================================================== --- branches/tmp/tgoettlicher/yast2cc_rewrite/src/main_window.cpp (original) +++ branches/tmp/tgoettlicher/yast2cc_rewrite/src/main_window.cpp Thu Jun 18 17:26:32 2009 @@ -144,7 +144,10 @@ qDebug() << "Scroll to :" << d->modmodel->groupsModel()->data(index).toString(); qDebug() << " 1st item :" << d->modmodel->data(modidx).toString(); if ( modidx.isValid() ) + { + d->modview->selectCategory( d->modmodel->groupsModel()->data(index).toString() ); d->modview->scrollTo(d->kcsfpm->mapFromSource(modidx)); + } } void MainWindow::slotModulePressed( const QModelIndex &index ) -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org