diff --git a/sidebar/CMakeLists.txt b/sidebar/CMakeLists.txt --- a/sidebar/CMakeLists.txt +++ b/sidebar/CMakeLists.txt @@ -1,8 +1,5 @@ set( sidebar_mode_srcs SidebarMode.cpp - CategoryDrawer.cpp - CategorizedView.cpp - SidebarDelegate.cpp ToolTips/tooltipmanager.cpp ) diff --git a/sidebar/CategorizedView.h b/sidebar/CategorizedView.h deleted file mode 100644 --- a/sidebar/CategorizedView.h +++ /dev/null @@ -1,35 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Rafael Fernández López * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * - ***************************************************************************/ - -#ifndef CATEGORIZEDVIEW_H -#define CATEGORIZEDVIEW_H - -#include - -class CategorizedView : public KCategorizedView -{ -public: - explicit CategorizedView( QWidget *parent = nullptr ); - - void setModel( QAbstractItemModel *model ) override; -protected: - void wheelEvent(QWheelEvent *) override; -}; - -#endif diff --git a/sidebar/CategorizedView.cpp b/sidebar/CategorizedView.cpp deleted file mode 100644 --- a/sidebar/CategorizedView.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Rafael Fernández López * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * - ***************************************************************************/ - -#include "CategorizedView.h" - -#include - -#include - -CategorizedView::CategorizedView( QWidget *parent ) - : KCategorizedView( parent ) -{ - setWordWrap( true ); - setViewportMargins(QMargins(0,0,-20,0)); -} - -void CategorizedView::setModel( QAbstractItemModel *model ) -{ - KCategorizedView::setModel( model ); -} - -void CategorizedView::wheelEvent(QWheelEvent* event) -{ - // this is a workaround because scrolling by mouse wheel is broken in Qt list views for big items - // https://bugreports.qt-project.org/browse/QTBUG-7232 - verticalScrollBar()->setSingleStep(10); - KCategorizedView::wheelEvent(event); -} diff --git a/sidebar/CategoryDrawer.h b/sidebar/CategoryDrawer.h deleted file mode 100644 --- a/sidebar/CategoryDrawer.h +++ /dev/null @@ -1,45 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Rafael Fernández López * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * - ***************************************************************************/ - -#ifndef CATEGORYDRAWER_H -#define CATEGORYDRAWER_H - -#include - -class QPainter; -class QModelIndex; -class QStyleOption; - -class CategoryDrawer : public KCategoryDrawer -{ - Q_OBJECT -public: - explicit CategoryDrawer(KCategorizedView *view); - - void drawCategory(const QModelIndex &index, - int sortRole, - const QStyleOption &option, - QPainter *painter) const override; - - int categoryHeight(const QModelIndex &index, const QStyleOption &option) const override; - int leftMargin() const override; - int rightMargin() const override; -}; - -#endif diff --git a/sidebar/CategoryDrawer.cpp b/sidebar/CategoryDrawer.cpp deleted file mode 100644 --- a/sidebar/CategoryDrawer.cpp +++ /dev/null @@ -1,93 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Rafael Fernández López * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * - ***************************************************************************/ - -#include "CategoryDrawer.h" - -#include "MenuProxyModel.h" - -#include -#include -#include - -CategoryDrawer::CategoryDrawer(KCategorizedView *view) -: KCategoryDrawer(view) -{ -} - -void CategoryDrawer::drawCategory(const QModelIndex &index, - int sortRole, - const QStyleOption &option, - QPainter *painter) const -{ - Q_UNUSED( option ) - Q_UNUSED( painter ) - Q_UNUSED( sortRole ) - - painter->setRenderHint(QPainter::Antialiasing); - - QFont font(QApplication::font()); - font.setBold(true); - const QFontMetrics fontMetrics = QFontMetrics(font); - const int height = categoryHeight(index, option); - - - const QString category = index.model()->data(index, KCategorizedSortFilterProxyModel::CategoryDisplayRole).toString(); - QRect textRect = QRect(option.rect.topLeft()+QPoint(8,0), QSize(option.rect.width() - 2 - 3 - 3, height)); - - textRect.setLeft(textRect.left()); - painter->save(); - painter->setFont(font); - QColor penColor(option.palette.text().color()); - penColor.setAlphaF(0.6); - painter->setPen(penColor); - if (index.row() > 0) { - textRect.setTop(textRect.top() + 10); - painter->save(); - penColor.setAlphaF(0.3); - painter->fillRect(QRect(textRect.topLeft() + QPoint(-8, -5), QSize(option.rect.width(),1)), penColor); - painter->restore(); - } - - painter->drawText(textRect, Qt::AlignLeft | Qt::AlignBottom, category); - painter->restore(); - -} - -int CategoryDrawer::categoryHeight(const QModelIndex &index, const QStyleOption &option) const -{ - Q_UNUSED( index ); - Q_UNUSED( option ); - - QFont font(QApplication::font()); - font.setBold(true); - const QFontMetrics fontMetrics = QFontMetrics(font); - //if (index.row() == 0) return fontMetrics.height(); - - return fontMetrics.height() * 1.6 /* vertical spacing */; -} - -int CategoryDrawer::leftMargin() const -{ - return 0; -} - -int CategoryDrawer::rightMargin() const -{ - return 0; -} diff --git a/sidebar/SidebarDelegate.h b/sidebar/SidebarDelegate.h deleted file mode 100644 --- a/sidebar/SidebarDelegate.h +++ /dev/null @@ -1,44 +0,0 @@ -/************************************************************************** - * Copyright (C) 2017 Marco Martin * - * * - * This program is free software; you can redistribute it and/or * - * modify it under the terms of the GNU General Public License * - * as published by the Free Software Foundation; either version 2 * - * of the License, or (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the Free Software * - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * - * 02110-1301, USA. * -***************************************************************************/ - -#ifndef SIDEBARDELEGATE_H -#define SIDEBARDELEGATE_H - -#include - -class SidebarDelegate : public QAbstractItemDelegate -{ - Q_OBJECT - -public: - explicit SidebarDelegate(QObject *parent = nullptr); - ~SidebarDelegate() override; - - - QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override; - - void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override; - -protected: - void initStyleOption(QStyleOptionViewItem *option, const QModelIndex &index) const; - QBrush foregroundBrush(const QStyleOptionViewItem &option, const QModelIndex &index) const; -}; - -#endif - diff --git a/sidebar/SidebarDelegate.cpp b/sidebar/SidebarDelegate.cpp deleted file mode 100644 --- a/sidebar/SidebarDelegate.cpp +++ /dev/null @@ -1,182 +0,0 @@ -/************************************************************************** - * Copyright (C) 2017 Marco Martin * - * * - * This program is free software; you can redistribute it and/or * - * modify it under the terms of the GNU General Public License * - * as published by the Free Software Foundation; either version 2 * - * of the License, or (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the Free Software * - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * - * 02110-1301, USA. * -***************************************************************************/ - -#include "SidebarDelegate.h" - -#include -#include - -static const int s_margin = 10; - -SidebarDelegate::SidebarDelegate(QObject *parent) - : QAbstractItemDelegate(parent) -{ -} - -SidebarDelegate::~SidebarDelegate() -{ -} - - -QSize SidebarDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const -{ - Q_UNUSED(index) - return QSize(option.decorationSize.width() + s_margin * 2, option.decorationSize.height() + s_margin * 2); -} - -void SidebarDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const -{ - Q_ASSERT(index.isValid()); - - painter->save(); - QStyleOptionViewItem opt = option; - initStyleOption(&opt, index); - - // Apparently some widget styles expect this hint to not be set - painter->setRenderHint(QPainter::Antialiasing, false); - - QStyle *style = option.widget ? option.widget->style() : QApplication::style(); - style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, opt.widget); - - painter->setRenderHint(QPainter::Antialiasing); - - QIcon::Mode iconMode; - - if (!(opt.state & QStyle::State_Enabled)) { - iconMode = QIcon::Disabled; - } else if ((opt.state & QStyle::State_Selected) && (opt.state & QStyle::State_Active)) { - iconMode = QIcon::Selected; - } else { - iconMode = QIcon::Normal; - } - - QIcon::State iconState = opt.state & QStyle::State_Open ? QIcon::On : QIcon::Off; - QPixmap icon = opt.icon.pixmap(opt.decorationSize, iconMode, iconState); - - const QRect iconRect = QStyle::alignedRect(opt.direction, Qt::AlignVCenter | Qt::AlignLeft, opt.decorationSize, opt.rect.adjusted(s_margin, s_margin, -s_margin, -s_margin)); - painter->drawPixmap(iconRect.topLeft(), icon); - - QFontMetrics fontMetrics(opt.font); - const QString text = fontMetrics.elidedText(opt.text, Qt::ElideRight, opt.rect.width() - iconRect.width() - s_margin*3); - //TODO: LTR - const QRect textRect = opt.rect.adjusted(s_margin + iconRect.right(), - s_margin, -s_margin, -s_margin); - - painter->setFont(opt.font); - painter->setPen(QPen(foregroundBrush(opt, index), 0)); - painter->drawText(textRect, Qt::AlignLeft | Qt::AlignVCenter, text); - painter->restore(); -} - -QBrush SidebarDelegate::foregroundBrush(const QStyleOptionViewItem &option, const QModelIndex &index) const -{ - Q_UNUSED(index); - QPalette::ColorGroup cg = QPalette::Active; - if (!(option.state & QStyle::State_Enabled)) { - cg = QPalette::Disabled; - } else if (!(option.state & QStyle::State_Active)) { - cg = QPalette::Inactive; - } - - // Always use the highlight color for selected items - if (option.state & QStyle::State_Selected) { - return option.palette.brush(cg, QPalette::HighlightedText); - } - - return option.palette.brush(cg, QPalette::Text); -} - -void SidebarDelegate::initStyleOption(QStyleOptionViewItem *option, - const QModelIndex &index) const -{ - QVariant value = index.data(Qt::FontRole); - if (value.isValid() && !value.isNull()) { - option->font = qvariant_cast(value).resolve(option->font); - option->fontMetrics = QFontMetrics(option->font); - } - - value = index.data(Qt::TextAlignmentRole); - if (value.isValid() && !value.isNull()) - option->displayAlignment = Qt::Alignment(value.toInt()); - - value = index.data(Qt::ForegroundRole); - if (value.canConvert()) - option->palette.setBrush(QPalette::Text, qvariant_cast(value)); - - option->index = index; - value = index.data(Qt::CheckStateRole); - if (value.isValid() && !value.isNull()) { - option->features |= QStyleOptionViewItem::HasCheckIndicator; - option->checkState = static_cast(value.toInt()); - } - - value = index.data(Qt::DecorationRole); - if (value.isValid() && !value.isNull()) { - option->features |= QStyleOptionViewItem::HasDecoration; - switch (value.type()) { - case QVariant::Icon: { - option->icon = qvariant_cast(value); - QIcon::Mode mode; - if (!(option->state & QStyle::State_Enabled)) - mode = QIcon::Disabled; - else if (option->state & QStyle::State_Selected) - mode = QIcon::Selected; - else - mode = QIcon::Normal; - QIcon::State state = option->state & QStyle::State_Open ? QIcon::On : QIcon::Off; - QSize actualSize = option->icon.actualSize(option->decorationSize, mode, state); - // For highdpi icons actualSize might be larger than decorationSize, which we don't want. Clamp it to decorationSize. - option->decorationSize = QSize(qMin(option->decorationSize.width(), actualSize.width()), - qMin(option->decorationSize.height(), actualSize.height())); - break; - } - case QVariant::Color: { - QPixmap pixmap(option->decorationSize); - pixmap.fill(qvariant_cast(value)); - option->icon = QIcon(pixmap); - break; - } - case QVariant::Image: { - QImage image = qvariant_cast(value); - option->icon = QIcon(QPixmap::fromImage(image)); - option->decorationSize = image.size() / image.devicePixelRatio(); - break; - } - case QVariant::Pixmap: { - QPixmap pixmap = qvariant_cast(value); - option->icon = QIcon(pixmap); - option->decorationSize = pixmap.size() / pixmap.devicePixelRatio(); - break; - } - default: - break; - } - } - - value = index.data(Qt::DisplayRole); - if (value.isValid() && !value.isNull()) { - option->features |= QStyleOptionViewItem::HasDisplay; - option->text = value.toString(); - } - - option->backgroundBrush = qvariant_cast(index.data(Qt::BackgroundRole)); - - // disable style animations for checkboxes etc. within itemviews (QTBUG-30146) - option->styleObject = nullptr; -} diff --git a/sidebar/SidebarMode.cpp b/sidebar/SidebarMode.cpp --- a/sidebar/SidebarMode.cpp +++ b/sidebar/SidebarMode.cpp @@ -18,15 +18,12 @@ ***************************************************************************/ #include "SidebarMode.h" -#include "CategoryDrawer.h" -#include "CategorizedView.h" #include "MenuItem.h" #include "MenuModel.h" #include "ModuleView.h" #include "MenuProxyModel.h" #include "BaseData.h" -#include "SidebarDelegate.h" #include "ToolTips/tooltipmanager.h" #include