Fixes, fixes, fixes:

* Better item appearance (selected and hover) on systemsettings.
* Keyboard navigation improved in dolphin, and now is possible to navigate with keyboard in systemsettings (it was not possible before).
* No rubberband or multiple selection on systemsettings.
* Single or double click for item activation depends on the system state on systemsettings.
* On KCategoryDrawer now titles are drawn with more margin, as happens on DolphinCategoryDrawer. This gives more consistency to its look.

CCMAIL: wstephenson@kde.org

svn path=/trunk/KDE/kdebase/apps/; revision=752784
This commit is contained in:
Rafael Fernández López 2007-12-25 17:37:41 +00:00
parent 8ded05f86d
commit e4170c1910
2 changed files with 61 additions and 42 deletions

View file

@ -365,19 +365,21 @@ void KCategorizedView::Private::drawNewCategory(const QModelIndex &index,
optionCopy.state &= ~QStyle::State_Selected;
if ((category == hoveredCategory) && !mouseButtonPressed)
{
optionCopy.state |= QStyle::State_MouseOver;
}
else if ((category == hoveredCategory) && mouseButtonPressed)
{
QPoint initialPressPosition = listView->viewport()->mapFromGlobal(QCursor::pos());
initialPressPosition.setY(initialPressPosition.y() + listView->verticalOffset());
initialPressPosition.setX(initialPressPosition.x() + listView->horizontalOffset());
if (initialPressPosition == this->initialPressPosition)
if ((listView->selectionMode() != SingleSelection) && (listView->selectionMode() != NoSelection)) {
if ((category == hoveredCategory) && !mouseButtonPressed)
{
optionCopy.state |= QStyle::State_Selected;
optionCopy.state |= QStyle::State_MouseOver;
}
else if ((category == hoveredCategory) && mouseButtonPressed)
{
QPoint initialPressPosition = listView->viewport()->mapFromGlobal(QCursor::pos());
initialPressPosition.setY(initialPressPosition.y() + listView->verticalOffset());
initialPressPosition.setX(initialPressPosition.x() + listView->horizontalOffset());
if (initialPressPosition == this->initialPressPosition)
{
optionCopy.state |= QStyle::State_Selected;
}
}
}
@ -774,39 +776,42 @@ void KCategorizedView::paintEvent(QPaintEvent *event)
else if (intersectedInThePast)
{
break; // the visible area has been finished, we don't need to keep asking, the rest won't intersect
// this is doable because we know that categories are correctly ordered on the list
// this is doable because we know that categories are correctly ordered on the list
}
}
if (d->mouseButtonPressed && !d->isDragging)
if ((selectionMode() != SingleSelection) && (selectionMode() != NoSelection))
{
QPoint start, end, initialPressPosition;
initialPressPosition = d->initialPressPosition;
initialPressPosition.setY(initialPressPosition.y() - verticalOffset());
initialPressPosition.setX(initialPressPosition.x() - horizontalOffset());
if (d->initialPressPosition.x() > d->mousePosition.x() ||
d->initialPressPosition.y() > d->mousePosition.y())
if (d->mouseButtonPressed && !d->isDragging)
{
start = d->mousePosition;
end = initialPressPosition;
}
else
{
start = initialPressPosition;
end = d->mousePosition;
}
QPoint start, end, initialPressPosition;
QStyleOptionRubberBand yetAnotherOption;
yetAnotherOption.initFrom(this);
yetAnotherOption.shape = QRubberBand::Rectangle;
yetAnotherOption.opaque = false;
yetAnotherOption.rect = QRect(start, end).intersected(viewport()->rect().adjusted(-16, -16, 16, 16));
painter.save();
style()->drawControl(QStyle::CE_RubberBand, &yetAnotherOption, &painter);
painter.restore();
initialPressPosition = d->initialPressPosition;
initialPressPosition.setY(initialPressPosition.y() - verticalOffset());
initialPressPosition.setX(initialPressPosition.x() - horizontalOffset());
if (d->initialPressPosition.x() > d->mousePosition.x() ||
d->initialPressPosition.y() > d->mousePosition.y())
{
start = d->mousePosition;
end = initialPressPosition;
}
else
{
start = initialPressPosition;
end = d->mousePosition;
}
QStyleOptionRubberBand yetAnotherOption;
yetAnotherOption.initFrom(this);
yetAnotherOption.shape = QRubberBand::Rectangle;
yetAnotherOption.opaque = false;
yetAnotherOption.rect = QRect(start, end).intersected(viewport()->rect().adjusted(-16, -16, 16, 16));
painter.save();
style()->drawControl(QStyle::CE_RubberBand, &yetAnotherOption, &painter);
painter.restore();
}
}
if (d->isDragging && !d->dragLeftViewport)
@ -1090,7 +1095,8 @@ void KCategorizedView::mouseReleaseEvent(QMouseEvent *event)
initialPressPosition.setY(initialPressPosition.y() + verticalOffset());
initialPressPosition.setX(initialPressPosition.x() + horizontalOffset());
if (initialPressPosition == d->initialPressPosition)
if ((selectionMode() != SingleSelection) && (selectionMode() != NoSelection) &&
(initialPressPosition == d->initialPressPosition))
{
foreach(const QString &category, d->categories)
{
@ -1570,7 +1576,8 @@ void KCategorizedView::currentChanged(const QModelIndex &current,
if (!elementsPerRow)
elementsPerRow++;
d->forcedSelectionPosition = d->elementsInfo[current.row()].relativeOffsetToCategory % elementsPerRow;
if (d->mouseButtonPressed || d->rightMouseButtonPressed)
d->forcedSelectionPosition = d->elementsInfo[current.row()].relativeOffsetToCategory % elementsPerRow;
QListView::currentChanged(current, previous);
}

View file

@ -23,6 +23,7 @@
#include <QPainter>
#include <QStyleOption>
#include <kiconloader.h>
#include <kcategorizedsortfilterproxymodel.h>
KCategoryDrawer::KCategoryDrawer()
@ -61,6 +62,17 @@ void KCategoryDrawer::drawCategory(const QModelIndex &index,
opt.direction = option.direction;
opt.text = category;
int iconSize = KIconLoader::global()->currentSize(KIconLoader::Small);
if (option.direction == Qt::LeftToRight)
{
opt.rect.setLeft(opt.rect.left() + (iconSize / 4));
}
else
{
opt.rect.setRight(opt.rect.width() - (iconSize / 4));
}
if (option.state & QStyle::State_Selected)
{
QColor selected = option.palette.color(QPalette::Highlight);
@ -113,7 +125,7 @@ void KCategoryDrawer::drawCategory(const QModelIndex &index,
painter->setPen(color);
painter->drawText(option.rect, Qt::AlignVCenter | Qt::AlignLeft,
painter->drawText(opt.rect, Qt::AlignVCenter | Qt::AlignLeft,
metrics.elidedText(category, Qt::ElideRight, option.rect.width()));
painter->restore();