Import of the Plasma Applet browser into the libplasma
svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=717167
This commit is contained in:
parent
1efc829861
commit
49b3e4b13b
@ -3,6 +3,7 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${KDEBASE_WORKSPACE_SOURCE_DIR}/
|
||||
find_package(OpenGL)
|
||||
|
||||
add_subdirectory( widgets )
|
||||
#add_subdirectory( appletbrowser )
|
||||
|
||||
########### next target ###############
|
||||
|
||||
@ -52,6 +53,19 @@ set(plasma_LIB_SRCS
|
||||
widgets/widget.cpp
|
||||
widgets/signalplotter.cpp
|
||||
widgets/meter.cpp
|
||||
|
||||
appletbrowser.cpp
|
||||
appletbrowser/appletbrowserwindow.cpp
|
||||
appletbrowser/kcategorizeditemsview.cpp
|
||||
appletbrowser/kcategorizeditemsviewdelegate.cpp
|
||||
appletbrowser/kcategorizeditemsviewmodels.cpp
|
||||
appletbrowser/plasmaappletitemmodel.cpp
|
||||
)
|
||||
|
||||
kde4_add_ui_files(
|
||||
plasma_LIB_SRCS
|
||||
appletbrowser/kcategorizeditemsviewbase.ui
|
||||
appletbrowser/appletbrowserwindowbase.ui
|
||||
)
|
||||
|
||||
set(krunner_xml ${KDEBASE_WORKSPACE_SOURCE_DIR}/krunner/org.kde.krunner.Interface.xml)
|
||||
@ -92,6 +106,7 @@ set(plasma_LIB_INCLUDES
|
||||
abstractrunner.h
|
||||
animator.h
|
||||
applet.h
|
||||
appletbrowser.h
|
||||
configxml.h
|
||||
containment.h
|
||||
corona.h
|
||||
|
16
appletbrowser/CMakeLists.txt
Normal file
16
appletbrowser/CMakeLists.txt
Normal file
@ -0,0 +1,16 @@
|
||||
|
||||
set(
|
||||
plasma_appletbrowser_SRCS
|
||||
kcategorizeditemsview.cpp
|
||||
kcategorizeditemsviewmodels.cpp
|
||||
kcategorizeditemsviewdelegate.cpp
|
||||
appletbrowserwindow.cpp
|
||||
plasmaappletitemmodel.cpp
|
||||
)
|
||||
|
||||
kde4_add_ui_files(
|
||||
plasma_appletbrowser_SRCS
|
||||
kcategorizeditemsviewbase.ui
|
||||
appletbrowserwindowbase.ui
|
||||
)
|
||||
|
26
appletbrowser/CMakeLists.txt.backup
Normal file
26
appletbrowser/CMakeLists.txt.backup
Normal file
@ -0,0 +1,26 @@
|
||||
project(PlasmaAppletBrowser)
|
||||
|
||||
include_directories(${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} ${KDE4_INCLUDES} ${PLASMA_INCLUDE_DIR})
|
||||
|
||||
set(
|
||||
plasma_appletbrowser_SRCS
|
||||
main.cpp
|
||||
kcategorizeditemsview.cpp
|
||||
kcategorizeditemsviewmodels.cpp
|
||||
kcategorizeditemsviewdelegate.cpp
|
||||
appletbrowserwindow.cpp
|
||||
plasmaappletitemmodel.cpp
|
||||
)
|
||||
|
||||
kde4_add_ui_files(
|
||||
plasma_appletbrowser_SRCS
|
||||
kcategorizeditemsviewbase.ui
|
||||
appletbrowserwindowbase.ui
|
||||
)
|
||||
|
||||
kde4_add_executable(plasmaappletbrowser ${plasma_appletbrowser_SRCS})
|
||||
|
||||
target_link_libraries(plasmaappletbrowser ${KDE4_KDEUI_LIBS} ${PLASMA_LIBS})
|
||||
|
||||
########### install applicaiton ###############
|
||||
install(TARGETS plasmaappletbrowser DESTINATION ${BIN_INSTALL_DIR} )
|
2
appletbrowser/Messages.sh
Executable file
2
appletbrowser/Messages.sh
Executable file
@ -0,0 +1,2 @@
|
||||
#! /usr/bin/env bash
|
||||
$XGETTEXT *.cpp -o $podir/plasmaappletbrowser.pot
|
16
appletbrowser/TODO
Normal file
16
appletbrowser/TODO
Normal file
@ -0,0 +1,16 @@
|
||||
* Bug [LOW]: items deselect if a user changes one
|
||||
of the stars of selected items
|
||||
|
||||
Not before it goes into plasma:
|
||||
* Adding multiple items
|
||||
* Dragging the schreenshots of plasmoids
|
||||
* Customized recommended by
|
||||
* GHNS
|
||||
|
||||
Done:
|
||||
* Bug [MEDIUM]: items select when the star is clicked
|
||||
* Feedback on hovering the star
|
||||
* The rest of the dialog - buttons, etc.
|
||||
* Separate (visually) special and normal categories
|
||||
* Applets without an icon - default icon, category icon
|
||||
|
81
appletbrowser/appletbrowserwindow.cpp
Normal file
81
appletbrowser/appletbrowserwindow.cpp
Normal file
@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright (C) 2007 Ivan Cukic <ivan.cukic+kde@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 (or,
|
||||
* at your option, any later version) as published by the Free Software
|
||||
* Foundation
|
||||
*
|
||||
* 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 Library 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 "appletbrowserwindow.h"
|
||||
#include <KAction>
|
||||
#include <KStandardAction>
|
||||
|
||||
AppletBrowserWindow::AppletBrowserWindow(Plasma::Corona * corona, QWidget * parent, Qt::WindowFlags f) :
|
||||
QDialog(parent, f), m_corona(corona), m_containment(NULL), m_itemModel(this), m_filterModel(this)
|
||||
{
|
||||
init();
|
||||
}
|
||||
|
||||
AppletBrowserWindow::AppletBrowserWindow(Plasma::Containment * containment, QWidget * parent, Qt::WindowFlags f) :
|
||||
QDialog(parent, f), m_corona(NULL), m_containment(containment), m_itemModel(this), m_filterModel(this)
|
||||
{
|
||||
init();
|
||||
}
|
||||
|
||||
void AppletBrowserWindow::init() {
|
||||
setupUi(this);
|
||||
|
||||
QAction* quit = KStandardAction::quit(qApp, SLOT(quit()), this);
|
||||
this->addAction(quit);
|
||||
|
||||
// Emblems
|
||||
appletList->addEmblem(i18n("Recommended by KDE"), new KIcon("about-kde"),
|
||||
KCategorizedItemsViewModels::Filter("recommended", true));
|
||||
appletList->addEmblem(i18n("Used in past"), new KIcon("history"),
|
||||
KCategorizedItemsViewModels::Filter("used", true));
|
||||
|
||||
// Filters: Special
|
||||
m_filterModel.addFilter(i18n("All applets"),
|
||||
KCategorizedItemsViewModels::Filter(), new KIcon("application-x-plasma"));
|
||||
m_filterModel.addFilter(i18n("Recommended by KDE"),
|
||||
KCategorizedItemsViewModels::Filter("recommended", true), new KIcon("about-kde"));
|
||||
m_filterModel.addFilter(i18n("Favorites"),
|
||||
KCategorizedItemsViewModels::Filter("favorite", true), new KIcon("bookmark"));
|
||||
m_filterModel.addFilter(i18n("Used in past"),
|
||||
KCategorizedItemsViewModels::Filter("used", true), new KIcon("history"));
|
||||
|
||||
m_filterModel.addSeparator(i18n("Categories:"));
|
||||
|
||||
// Filters: Categories
|
||||
foreach (const QString& category, Plasma::Applet::knownCategories()) {
|
||||
m_filterModel.addFilter(category,
|
||||
KCategorizedItemsViewModels::Filter("category", category));
|
||||
}
|
||||
|
||||
appletList->setFilterModel(& m_filterModel);
|
||||
|
||||
// Other models
|
||||
|
||||
appletList->setItemModel(& m_itemModel);
|
||||
|
||||
}
|
||||
|
||||
AppletBrowserWindow::~AppletBrowserWindow()
|
||||
{
|
||||
/*delete m_itemModel;
|
||||
delete m_filterModel;
|
||||
delete m_proxyModel;*/
|
||||
}
|
||||
|
||||
#include "appletbrowserwindow.moc"
|
50
appletbrowser/appletbrowserwindow.h
Normal file
50
appletbrowser/appletbrowserwindow.h
Normal file
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (C) 2007 Ivan Cukic <ivan.cukic+kde@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 (or,
|
||||
* at your option, any later version) as published by the Free Software
|
||||
* Foundation
|
||||
*
|
||||
* 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 Library 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 APPLETBROWSERWINDOW_H_
|
||||
#define APPLETBROWSERWINDOW_H_
|
||||
|
||||
#include <QtGui>
|
||||
#include <QtCore>
|
||||
#include <iostream>
|
||||
#include "ui_appletbrowserwindowbase.h"
|
||||
|
||||
#include "plasmaappletitemmodel.h"
|
||||
#include "kcategorizeditemsview.h"
|
||||
|
||||
#include "../corona.h"
|
||||
#include "../containment.h"
|
||||
|
||||
class AppletBrowserWindow: public QDialog, public Ui::AppletBrowserWindowBase
|
||||
{
|
||||
//Q_OBJECT
|
||||
public:
|
||||
explicit AppletBrowserWindow(Plasma::Corona * corona, QWidget * parent = 0, Qt::WindowFlags f = 0);
|
||||
explicit AppletBrowserWindow(Plasma::Containment * containment, QWidget * parent = 0, Qt::WindowFlags f = 0);
|
||||
virtual ~AppletBrowserWindow();
|
||||
|
||||
private:
|
||||
void init();
|
||||
Plasma::Corona * m_corona;
|
||||
Plasma::Containment * m_containment;
|
||||
PlasmaAppletItemModel m_itemModel;
|
||||
KCategorizedItemsViewModels::DefaultFilterModel m_filterModel;
|
||||
};
|
||||
|
||||
#endif /*APPLETBROWSERWINDOW_H_*/
|
87
appletbrowser/appletbrowserwindowbase.ui
Normal file
87
appletbrowser/appletbrowserwindowbase.ui
Normal file
@ -0,0 +1,87 @@
|
||||
<ui version="4.0" >
|
||||
<class>AppletBrowserWindowBase</class>
|
||||
<widget class="QDialog" name="AppletBrowserWindowBase" >
|
||||
<property name="geometry" >
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>536</width>
|
||||
<height>441</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle" >
|
||||
<string>Dialog</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" >
|
||||
<item row="0" column="0" colspan="4" >
|
||||
<widget class="KCategorizedItemsView" native="1" name="appletList" />
|
||||
</item>
|
||||
<item row="1" column="0" >
|
||||
<widget class="QPushButton" name="buttonGHNS" >
|
||||
<property name="text" >
|
||||
<string>Download from Internet</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1" >
|
||||
<spacer>
|
||||
<property name="orientation" >
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" >
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="1" column="2" >
|
||||
<widget class="QPushButton" name="buttonAdd" >
|
||||
<property name="text" >
|
||||
<string>Add Applet</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="3" >
|
||||
<widget class="QPushButton" name="buttonClose" >
|
||||
<property name="text" >
|
||||
<string>Close</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>KCategorizedItemsView</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>appletbrowser/kcategorizeditemsview.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<tabstops>
|
||||
<tabstop>buttonAdd</tabstop>
|
||||
<tabstop>buttonClose</tabstop>
|
||||
<tabstop>buttonGHNS</tabstop>
|
||||
</tabstops>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonClose</sender>
|
||||
<signal>clicked()</signal>
|
||||
<receiver>AppletBrowserWindowBase</receiver>
|
||||
<slot>close()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel" >
|
||||
<x>491</x>
|
||||
<y>418</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel" >
|
||||
<x>494</x>
|
||||
<y>444</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
122
appletbrowser/kcategorizeditemsview.cpp
Normal file
122
appletbrowser/kcategorizeditemsview.cpp
Normal file
@ -0,0 +1,122 @@
|
||||
/*
|
||||
* Copyright (C) 2007 Ivan Cukic <ivan.cukic+kde@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 (or,
|
||||
* at your option, any later version) as published by the Free Software
|
||||
* Foundation
|
||||
*
|
||||
* 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 Library 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 "kcategorizeditemsview.h"
|
||||
#include "kcategorizeditemsviewdelegate.h"
|
||||
|
||||
#include <KIcon>
|
||||
#include <KDebug>
|
||||
#include <KAction>
|
||||
#include <KStandardAction>
|
||||
|
||||
KCategorizedItemsView::KCategorizedItemsView(QWidget * parent, Qt::WindowFlags f)
|
||||
: QWidget(parent, f), m_modelCategories(NULL), m_modelFilters(NULL),
|
||||
m_modelItems(NULL), m_modelFilterItems(NULL), m_delegate(NULL)
|
||||
{
|
||||
setupUi(this);
|
||||
textSearch->setClickMessage(i18n("Enter search phrase here"));
|
||||
|
||||
connect(textSearch, SIGNAL(textChanged(QString)),
|
||||
this, SLOT(searchTermChanged(QString)));
|
||||
connect(comboFilters, SIGNAL(currentIndexChanged(int)),
|
||||
this, SLOT(filterChanged(int)));
|
||||
|
||||
connect (itemsView, SIGNAL(activated(const QModelIndex &)),
|
||||
this, SIGNAL(activated(const QModelIndex &)));
|
||||
|
||||
connect (itemsView, SIGNAL(clicked(const QModelIndex &)),
|
||||
this, SIGNAL(clicked(const QModelIndex &)));
|
||||
connect (itemsView, SIGNAL(entered(const QModelIndex &)),
|
||||
this, SIGNAL(entered(const QModelIndex &)));
|
||||
connect (itemsView, SIGNAL(pressed(const QModelIndex &)),
|
||||
this, SIGNAL(pressed(const QModelIndex &)));
|
||||
|
||||
itemsView->header()->setVisible(false);
|
||||
|
||||
itemsView->setItemDelegate(m_delegate = new KCategorizedItemsViewDelegate(this));
|
||||
|
||||
comboFilters->setItemDelegate(new KCategorizedItemsViewFilterDelegate(this));
|
||||
|
||||
itemsView->viewport()->setAttribute(Qt::WA_Hover);
|
||||
|
||||
QAction * find = KStandardAction::find(textSearch, SLOT(setFocus()), this);
|
||||
addAction(find);
|
||||
resizeEvent(NULL);
|
||||
}
|
||||
|
||||
KCategorizedItemsView::~KCategorizedItemsView() {
|
||||
delete m_modelFilterItems;
|
||||
delete m_delegate;
|
||||
}
|
||||
|
||||
void KCategorizedItemsView::paintEvent ( QPaintEvent * event ) {
|
||||
Q_UNUSED(event);
|
||||
resizeEvent(NULL);
|
||||
}
|
||||
|
||||
void KCategorizedItemsView::resizeEvent ( QResizeEvent * event ) {
|
||||
Q_UNUSED(event);
|
||||
if (m_viewWidth == itemsView->viewport()->width()) return;
|
||||
m_viewWidth = itemsView->viewport()->width();
|
||||
itemsView->setColumnWidth(0, m_delegate->columnWidth(0, m_viewWidth));
|
||||
itemsView->setColumnWidth(1, m_delegate->columnWidth(1, m_viewWidth));
|
||||
}
|
||||
|
||||
void KCategorizedItemsView::setFilterModel(QStandardItemModel * model)
|
||||
{
|
||||
comboFilters->setModel(model);
|
||||
m_modelFilters = model;
|
||||
}
|
||||
|
||||
void KCategorizedItemsView::setItemModel(QStandardItemModel * model)
|
||||
{
|
||||
if (!m_modelFilterItems) m_modelFilterItems = new DefaultItemFilterProxyModel(this);
|
||||
|
||||
m_modelItems = model;
|
||||
m_modelFilterItems->setSourceModel(m_modelItems);
|
||||
|
||||
itemsView->setModel(m_modelFilterItems);
|
||||
}
|
||||
|
||||
void KCategorizedItemsView::searchTermChanged(const QString & text)
|
||||
{
|
||||
kDebug() << "EVENT\n" << text;
|
||||
if (m_modelFilterItems) {
|
||||
m_modelFilterItems->setSearch(text);
|
||||
}
|
||||
}
|
||||
|
||||
void KCategorizedItemsView::filterChanged(int index)
|
||||
{
|
||||
if (m_modelFilterItems) {
|
||||
QVariant data = m_modelFilters->item(index)->data();
|
||||
m_modelFilterItems->setFilter(qVariantValue<KCategorizedItemsViewModels::Filter>(data));
|
||||
}
|
||||
}
|
||||
|
||||
void KCategorizedItemsView::addEmblem(const QString & title, QIcon * icon, const Filter & filter) {
|
||||
m_emblems[title] = QPair<Filter, QIcon *>(filter, icon);
|
||||
}
|
||||
|
||||
void KCategorizedItemsView::clearEmblems() {
|
||||
m_emblems.clear();
|
||||
}
|
||||
|
||||
#include "kcategorizeditemsview.moc"
|
||||
|
91
appletbrowser/kcategorizeditemsview.h
Normal file
91
appletbrowser/kcategorizeditemsview.h
Normal file
@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Copyright (C) 2007 Ivan Cukic <ivan.cukic+kde@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 (or,
|
||||
* at your option, any later version) as published by the Free Software
|
||||
* Foundation
|
||||
*
|
||||
* 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 Library 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 KCategorizedItemsView_H
|
||||
#define KCategorizedItemsView_H
|
||||
|
||||
#include <QtGui>
|
||||
#include <QtCore>
|
||||
#include <iostream>
|
||||
#include "kcategorizeditemsviewmodels.h"
|
||||
|
||||
#include "ui_kcategorizeditemsviewbase.h"
|
||||
|
||||
using namespace KCategorizedItemsViewModels;
|
||||
class KCategorizedItemsViewDelegate;
|
||||
|
||||
/**
|
||||
* QT4 View Widget for displaying a list of categorized items with special
|
||||
* filtering capabilities.
|
||||
*
|
||||
* To use it, you need to implement KCategorizedItemsView::AbstractItem
|
||||
*
|
||||
* For convenience, there are default implementations of category model
|
||||
* (DefaultCategoryModel), filters model (DefaultFilterModel) and the
|
||||
* default item mode (DefaultItemModel), but you do not need to use them.
|
||||
*
|
||||
* One constraint is that DefaultItemModel *must* hold the items that
|
||||
* are subclassed from KCategorizedItemsView::AbstractItem
|
||||
*
|
||||
*/
|
||||
class KCategorizedItemsView: public QWidget, public Ui::KCategorizedItemsViewBase
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
||||
KCategorizedItemsView(QWidget * parent = 0, Qt::WindowFlags f = 0);
|
||||
virtual ~KCategorizedItemsView();
|
||||
|
||||
void setFilterModel(QStandardItemModel * model); ///< Sets the filters model
|
||||
void setItemModel(QStandardItemModel * model); ///< Sets the item model, as mentioned items must implement AbstractItem class
|
||||
|
||||
void addEmblem(const QString & title, QIcon * icon, const Filter & filter);
|
||||
void clearEmblems();
|
||||
|
||||
protected slots:
|
||||
void searchTermChanged(const QString &text);
|
||||
void filterChanged(int index);
|
||||
void resizeEvent ( QResizeEvent * event );
|
||||
void paintEvent ( QPaintEvent * event );
|
||||
|
||||
Q_SIGNALS:
|
||||
void activated ( const QModelIndex & index );
|
||||
void clicked ( const QModelIndex & index );
|
||||
void doubleClicked ( const QModelIndex & index );
|
||||
void entered ( const QModelIndex & index );
|
||||
void pressed ( const QModelIndex & index );
|
||||
|
||||
private:
|
||||
QStandardItemModel * m_modelCategories;
|
||||
QStandardItemModel * m_modelFilters;
|
||||
QStandardItemModel * m_modelItems;
|
||||
|
||||
DefaultItemFilterProxyModel * m_modelFilterItems;
|
||||
KCategorizedItemsViewDelegate * m_delegate;
|
||||
|
||||
int m_viewWidth;
|
||||
|
||||
QMap < QString, QPair < Filter, QIcon * > > m_emblems;
|
||||
|
||||
friend class KCategorizedItemsViewDelegate;
|
||||
};
|
||||
|
||||
//Q_DECLARE_METATYPE(KCategorizedItemsView::Filter)
|
||||
|
||||
#endif
|
151
appletbrowser/kcategorizeditemsviewbase.ui
Normal file
151
appletbrowser/kcategorizeditemsviewbase.ui
Normal file
@ -0,0 +1,151 @@
|
||||
<ui version="4.0" >
|
||||
<class>KCategorizedItemsViewBase</class>
|
||||
<widget class="QWidget" name="KCategorizedItemsViewBase" >
|
||||
<property name="geometry" >
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>487</width>
|
||||
<height>528</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" >
|
||||
<property name="leftMargin" >
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin" >
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin" >
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin" >
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QComboBox" name="comboFilters" >
|
||||
<property name="sizePolicy" >
|
||||
<sizepolicy vsizetype="Fixed" hsizetype="Expanding" >
|
||||
<horstretch>3</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QFrame" name="frame" >
|
||||
<property name="frameShape" >
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow" >
|
||||
<enum>QFrame::Sunken</enum>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" >
|
||||
<property name="spacing" >
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="leftMargin" >
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin" >
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin" >
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin" >
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="KLineEdit" name="textSearch" >
|
||||
<property name="sizePolicy" >
|
||||
<sizepolicy vsizetype="Fixed" hsizetype="Expanding" >
|
||||
<horstretch>2</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="frame" >
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="showClearButton" stdset="0" >
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Line" name="line" >
|
||||
<property name="frameShadow" >
|
||||
<enum>QFrame::Plain</enum>
|
||||
</property>
|
||||
<property name="orientation" >
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTreeView" name="itemsView" >
|
||||
<property name="frameShape" >
|
||||
<enum>QFrame::NoFrame</enum>
|
||||
</property>
|
||||
<property name="editTriggers" >
|
||||
<set>QAbstractItemView::NoEditTriggers</set>
|
||||
</property>
|
||||
<property name="dragEnabled" >
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="dragDropMode" >
|
||||
<enum>QAbstractItemView::DragOnly</enum>
|
||||
</property>
|
||||
<property name="selectionMode" >
|
||||
<enum>QAbstractItemView::ExtendedSelection</enum>
|
||||
</property>
|
||||
<property name="iconSize" >
|
||||
<size>
|
||||
<width>64</width>
|
||||
<height>64</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="indentation" >
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rootIsDecorated" >
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11" />
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>KLineEdit</class>
|
||||
<extends>QLineEdit</extends>
|
||||
<header>klineedit.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<tabstops>
|
||||
<tabstop>comboFilters</tabstop>
|
||||
</tabstops>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>comboFilters</sender>
|
||||
<signal>currentIndexChanged(int)</signal>
|
||||
<receiver>textSearch</receiver>
|
||||
<slot>clear()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel" >
|
||||
<x>438</x>
|
||||
<y>14</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel" >
|
||||
<x>438</x>
|
||||
<y>38</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
281
appletbrowser/kcategorizeditemsviewdelegate.cpp
Normal file
281
appletbrowser/kcategorizeditemsviewdelegate.cpp
Normal file
@ -0,0 +1,281 @@
|
||||
/*
|
||||
* Copyright (C) 2007 Ivan Cukic <ivan.cukic+kde@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 (or,
|
||||
* at your option, any later version) as published by the Free Software
|
||||
* Foundation
|
||||
*
|
||||
* 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 Library 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 "kcategorizeditemsviewdelegate.h"
|
||||
#include "kcategorizeditemsview.h"
|
||||
#include <KIconLoader>
|
||||
#include <QtCore>
|
||||
#include <cmath>
|
||||
|
||||
#define FAV_ICON_SIZE 24
|
||||
#define EMBLEM_ICON_SIZE 16
|
||||
#define UNIVERSAL_PADDING 6
|
||||
#define FADE_LENGTH 32
|
||||
#define MAIN_ICON_SIZE 48
|
||||
#define DROPDOWN_PADDING 2
|
||||
#define DROPDOWN_SEPARATOR_HEIGHT 32
|
||||
|
||||
KCategorizedItemsViewDelegate::KCategorizedItemsViewDelegate(QObject * parent)
|
||||
: QItemDelegate(parent), m_favoriteIcon("bookmark"),
|
||||
m_favoriteAddIcon("edit-add"), m_favoriteRemoveIcon("edit-delete"),
|
||||
m_onFavoriteIconItem(NULL)
|
||||
{
|
||||
m_parent = (KCategorizedItemsView *) parent;
|
||||
}
|
||||
|
||||
void KCategorizedItemsViewDelegate::paint(QPainter *painter,
|
||||
const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||
{
|
||||
|
||||
// Preparing needed data for painting
|
||||
int left = option.rect.left();
|
||||
int top = option.rect.top();
|
||||
int width = option.rect.width();
|
||||
int height = option.rect.height();
|
||||
bool leftToRight = (painter->layoutDirection() == Qt::LeftToRight);
|
||||
|
||||
QIcon::Mode iconMode = QIcon::Normal;
|
||||
|
||||
QColor backgroundColor = (option.state.testFlag(QStyle::State_Selected))?
|
||||
option.palette.color(QPalette::Highlight):option.palette.color(QPalette::Base);
|
||||
QColor foregroundColor = (option.state.testFlag(QStyle::State_Selected))?
|
||||
option.palette.color(QPalette::HighlightedText):option.palette.color(QPalette::Text);
|
||||
|
||||
KCategorizedItemsViewModels::AbstractItem * item =
|
||||
getItemByProxyIndex(index);
|
||||
if (!item) return;
|
||||
|
||||
// Base Background
|
||||
painter->fillRect(option.rect, QBrush(backgroundColor));
|
||||
|
||||
if (index.column() == 0) {
|
||||
// Painting main column
|
||||
QStyleOptionViewItem local_option_title(option);
|
||||
QStyleOptionViewItem local_option_normal(option);
|
||||
|
||||
local_option_title.font.setBold(true);
|
||||
local_option_title.font.setPointSize(local_option_title.font.pointSize() + 2);
|
||||
|
||||
QLinearGradient gradient;
|
||||
|
||||
QString title = item->name();
|
||||
QString description = item->description();
|
||||
|
||||
// Painting
|
||||
|
||||
// Text
|
||||
int textInner = 2 * UNIVERSAL_PADDING + MAIN_ICON_SIZE;
|
||||
|
||||
painter->setPen(foregroundColor);
|
||||
painter->setFont(local_option_title.font);
|
||||
painter->drawText(
|
||||
left + (leftToRight ? textInner : 0),
|
||||
top + UNIVERSAL_PADDING,
|
||||
width - textInner, MAIN_ICON_SIZE / 2,
|
||||
Qt::AlignBottom | Qt::AlignLeft, title);
|
||||
painter->setFont(local_option_normal.font);
|
||||
painter->drawText(
|
||||
left + (leftToRight ? textInner : 0),
|
||||
top + UNIVERSAL_PADDING + MAIN_ICON_SIZE / 2,
|
||||
width - textInner, MAIN_ICON_SIZE / 2,
|
||||
Qt::AlignTop | Qt::AlignLeft, description);
|
||||
|
||||
// Main icon
|
||||
item->icon().paint(painter,
|
||||
leftToRight ? left + UNIVERSAL_PADDING : left + width - UNIVERSAL_PADDING - MAIN_ICON_SIZE,
|
||||
top + UNIVERSAL_PADDING,
|
||||
MAIN_ICON_SIZE, MAIN_ICON_SIZE, Qt::AlignCenter, iconMode);
|
||||
|
||||
// Counting the number of emblems for this item
|
||||
int emblemCount = 0;
|
||||
QPair < Filter, QIcon * > emblem;
|
||||
foreach (emblem, m_parent->m_emblems) {
|
||||
if (item->passesFiltering(emblem.first)) ++emblemCount;
|
||||
}
|
||||
|
||||
// Gradient part of the background - fading of the text at the end
|
||||
if (leftToRight) {
|
||||
gradient = QLinearGradient(left + width - UNIVERSAL_PADDING - FADE_LENGTH, 0,
|
||||
left + width - UNIVERSAL_PADDING, 0);
|
||||
gradient.setColorAt(1, backgroundColor);
|
||||
backgroundColor.setAlpha(0);
|
||||
gradient.setColorAt(0, backgroundColor);
|
||||
} else {
|
||||
gradient = QLinearGradient(left + UNIVERSAL_PADDING, 0,
|
||||
left + UNIVERSAL_PADDING + FADE_LENGTH, 0);
|
||||
gradient.setColorAt(0, backgroundColor);
|
||||
backgroundColor.setAlpha(0);
|
||||
gradient.setColorAt(1, backgroundColor);
|
||||
|
||||
}
|
||||
|
||||
QRect paintRect = option.rect;
|
||||
painter->setCompositionMode(QPainter::CompositionMode_SourceOver);
|
||||
painter->fillRect(paintRect, gradient);
|
||||
|
||||
if (leftToRight) {
|
||||
gradient.setStart(left + width
|
||||
- emblemCount * (UNIVERSAL_PADDING + EMBLEM_ICON_SIZE) - FADE_LENGTH, 0);
|
||||
gradient.setFinalStop(left + width
|
||||
- emblemCount * (UNIVERSAL_PADDING + EMBLEM_ICON_SIZE), 0);
|
||||
} else {
|
||||
gradient.setStart(left + UNIVERSAL_PADDING
|
||||
+ emblemCount * (UNIVERSAL_PADDING + EMBLEM_ICON_SIZE), 0);
|
||||
gradient.setFinalStop(left + UNIVERSAL_PADDING
|
||||
+ emblemCount * (UNIVERSAL_PADDING + EMBLEM_ICON_SIZE) + FADE_LENGTH, 0);
|
||||
}
|
||||
paintRect.setHeight(UNIVERSAL_PADDING + MAIN_ICON_SIZE / 2);
|
||||
painter->fillRect(paintRect, gradient);
|
||||
|
||||
// Emblems icons
|
||||
int emblemLeft = leftToRight ? (left + width - EMBLEM_ICON_SIZE) : left; // - FAV_ICON_SIZE - 2 * UNIVERSAL_PADDING
|
||||
foreach (emblem, m_parent->m_emblems) {
|
||||
if (item->passesFiltering(emblem.first)) {
|
||||
emblem.second->paint(painter,
|
||||
emblemLeft, top + UNIVERSAL_PADDING,
|
||||
EMBLEM_ICON_SIZE, EMBLEM_ICON_SIZE, Qt::AlignCenter, iconMode);
|
||||
if (leftToRight) {
|
||||
emblemLeft -= UNIVERSAL_PADDING + EMBLEM_ICON_SIZE;
|
||||
} else {
|
||||
emblemLeft += UNIVERSAL_PADDING + EMBLEM_ICON_SIZE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
// Painting favorite icon column
|
||||
|
||||
KCategorizedItemsViewModels::AbstractItem * item =
|
||||
getItemByProxyIndex(index);
|
||||
|
||||
if (! (option.state & QStyle::State_MouseOver) && m_onFavoriteIconItem == item)
|
||||
m_onFavoriteIconItem = NULL;
|
||||
|
||||
QIcon::Mode iconMode = QIcon::Normal;
|
||||
if (!item->isFavorite()) {
|
||||
iconMode = QIcon::Disabled;
|
||||
} else if (option.state & QStyle::State_MouseOver) {
|
||||
iconMode = QIcon::Active;
|
||||
}
|
||||
|
||||
m_favoriteIcon.paint(painter,
|
||||
left + width - FAV_ICON_SIZE - UNIVERSAL_PADDING, top + UNIVERSAL_PADDING,
|
||||
FAV_ICON_SIZE, FAV_ICON_SIZE, Qt::AlignCenter, iconMode);
|
||||
|
||||
const KIcon * icon = (item->isFavorite())? & m_favoriteRemoveIcon : & m_favoriteAddIcon;
|
||||
|
||||
if ((option.state & QStyle::State_MouseOver) && (m_onFavoriteIconItem != item))
|
||||
icon->paint(painter,
|
||||
left + width - EMBLEM_ICON_SIZE - UNIVERSAL_PADDING, top + UNIVERSAL_PADDING,
|
||||
EMBLEM_ICON_SIZE, EMBLEM_ICON_SIZE, Qt::AlignCenter, iconMode);
|
||||
|
||||
}
|
||||
|
||||
// Dividing line
|
||||
backgroundColor = option.palette.color(QPalette::Highlight);
|
||||
backgroundColor.setAlpha(100);
|
||||
painter->setPen(backgroundColor);
|
||||
painter->drawLine(left, top + height - 1, left + width, top + height - 1);
|
||||
|
||||
}
|
||||
|
||||
bool KCategorizedItemsViewDelegate::editorEvent(QEvent *event,
|
||||
QAbstractItemModel *model,
|
||||
const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index)
|
||||
{
|
||||
if (index.column() == 1 && event->type() == QEvent::MouseButtonPress) {
|
||||
(m_onFavoriteIconItem = getItemByProxyIndex(index))
|
||||
->setFavorite(!getItemByProxyIndex(index)->isFavorite());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return QItemDelegate::editorEvent(event, model, option, index);
|
||||
}
|
||||
|
||||
QSize KCategorizedItemsViewDelegate::sizeHint(const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index ) const
|
||||
{
|
||||
Q_UNUSED(option);
|
||||
|
||||
//Q_UNUSED(index);
|
||||
//option.
|
||||
int width = (index.column() == 0) ? 0 : FAV_ICON_SIZE;
|
||||
return QSize(width, MAIN_ICON_SIZE + 2 * UNIVERSAL_PADDING);
|
||||
}
|
||||
|
||||
int KCategorizedItemsViewDelegate::columnWidth (int column, int viewWidth) const {
|
||||
if (column == 1) {
|
||||
return FAV_ICON_SIZE + 2 * UNIVERSAL_PADDING;
|
||||
} else return viewWidth - columnWidth(1, viewWidth);
|
||||
}
|
||||
|
||||
|
||||
KCategorizedItemsViewModels::AbstractItem * KCategorizedItemsViewDelegate::getItemByProxyIndex(const QModelIndex & index) const {
|
||||
return (AbstractItem *) m_parent->m_modelItems->itemFromIndex(
|
||||
m_parent->m_modelFilterItems->mapToSource(index)
|
||||
);
|
||||
}
|
||||
|
||||
// KCategorizedItemsViewFilterDelegate
|
||||
|
||||
|
||||
KCategorizedItemsViewFilterDelegate::KCategorizedItemsViewFilterDelegate(QObject *parent)
|
||||
: QItemDelegate(parent) {
|
||||
kDebug() << "KCategorizedItemsViewFilterDelegate(QObject *parent)\n";
|
||||
|
||||
}
|
||||
|
||||
void KCategorizedItemsViewFilterDelegate::paint(QPainter *painter,
|
||||
const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||
{
|
||||
if (index.flags() & Qt::ItemIsEnabled) {
|
||||
QItemDelegate::paint(painter, option, index);
|
||||
} else {
|
||||
QStyleOptionViewItem separatorOption(option);
|
||||
int height = QItemDelegate::sizeHint(option, index).height() + 2 * DROPDOWN_PADDING;
|
||||
|
||||
separatorOption.state &= ~(QStyle::State_Selected
|
||||
| QStyle::State_MouseOver | QStyle::State_HasFocus);
|
||||
separatorOption.rect.setTop(separatorOption.rect.top() + separatorOption.rect.height() - height);
|
||||
separatorOption.rect.setHeight(height);
|
||||
QItemDelegate::paint(painter, separatorOption, index);
|
||||
/*painter->drawLine(
|
||||
option.rect.left(),
|
||||
option.rect.top() + 1,
|
||||
option.rect.left() + option.rect.width(),
|
||||
option.rect.top() + 1);*/
|
||||
}
|
||||
}
|
||||
|
||||
QSize KCategorizedItemsViewFilterDelegate::sizeHint(const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index ) const
|
||||
{
|
||||
QSize size = QItemDelegate::sizeHint(option, index);
|
||||
if (index.flags() & Qt::ItemIsEnabled) {
|
||||
size.setHeight(size.height() + 2 * DROPDOWN_PADDING);
|
||||
} else {
|
||||
size.setHeight(DROPDOWN_SEPARATOR_HEIGHT);
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
#include "kcategorizeditemsviewdelegate.moc"
|
||||
|
80
appletbrowser/kcategorizeditemsviewdelegate.h
Normal file
80
appletbrowser/kcategorizeditemsviewdelegate.h
Normal file
@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright (C) 2007 Ivan Cukic <ivan.cukic+kde@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 (or,
|
||||
* at your option, any later version) as published by the Free Software
|
||||
* Foundation
|
||||
*
|
||||
* 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 Library 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 KCATEGORIZEDITEMSVIEWDELEGATE_H_
|
||||
#define KCATEGORIZEDITEMSVIEWDELEGATE_H_
|
||||
|
||||
#include <QtCore>
|
||||
#include <QtGui>
|
||||
#include <KIcon>
|
||||
#include "kcategorizeditemsviewmodels.h"
|
||||
|
||||
class KCategorizedItemsView;
|
||||
|
||||
namespace KCategorizedItemsViewModels {
|
||||
class AbstractItem;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delegate for displaying the items
|
||||
*/
|
||||
class KCategorizedItemsViewDelegate: public QItemDelegate
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
KCategorizedItemsViewDelegate(QObject *parent = 0);
|
||||
|
||||
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||
QSize sizeHint ( const QStyleOptionViewItem & option, const QModelIndex & index ) const;
|
||||
int columnWidth (int column, int viewWidth) const;
|
||||
|
||||
bool editorEvent(QEvent *event,
|
||||
QAbstractItemModel *model,
|
||||
const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index);
|
||||
|
||||
private:
|
||||
|
||||
KCategorizedItemsView * m_parent;
|
||||
KIcon m_favoriteIcon;
|
||||
KIcon m_favoriteAddIcon;
|
||||
KIcon m_favoriteRemoveIcon;
|
||||
|
||||
mutable KCategorizedItemsViewModels::AbstractItem * m_onFavoriteIconItem;
|
||||
|
||||
|
||||
KCategorizedItemsViewModels::AbstractItem * getItemByProxyIndex(const QModelIndex & index) const;
|
||||
};
|
||||
|
||||
/**
|
||||
* Delegate for displaying the filters/categories
|
||||
*/
|
||||
class KCategorizedItemsViewFilterDelegate: public QItemDelegate
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
KCategorizedItemsViewFilterDelegate(QObject *parent = 0);
|
||||
|
||||
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||
QSize sizeHint ( const QStyleOptionViewItem & option, const QModelIndex & index ) const;
|
||||
};
|
||||
|
||||
#endif /*KCATEGORIZEDITEMSVIEWDELEGATE_H_*/
|
249
appletbrowser/kcategorizeditemsviewmodels.cpp
Normal file
249
appletbrowser/kcategorizeditemsviewmodels.cpp
Normal file
@ -0,0 +1,249 @@
|
||||
/*
|
||||
* Copyright (C) 2007 Ivan Cukic <ivan.cukic+kde@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 (or,
|
||||
* at your option, any later version) as published by the Free Software
|
||||
* Foundation
|
||||
*
|
||||
* 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 Library 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 "kcategorizeditemsviewmodels.h"
|
||||
|
||||
namespace KCategorizedItemsViewModels {
|
||||
|
||||
// AbstractItem
|
||||
|
||||
QString AbstractItem::name() const
|
||||
{
|
||||
return text();
|
||||
}
|
||||
|
||||
QString AbstractItem::description() const
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
bool AbstractItem::isFavorite() const
|
||||
{
|
||||
return passesFiltering(Filter("favorite", true));
|
||||
}
|
||||
|
||||
bool AbstractItem::matches(const QString & pattern) const
|
||||
{
|
||||
return name().contains(pattern, Qt::CaseInsensitive) || description().contains(pattern, Qt::CaseInsensitive);
|
||||
}
|
||||
|
||||
// DefaultFilterModel
|
||||
|
||||
DefaultFilterModel::DefaultFilterModel(QObject * parent) :
|
||||
QStandardItemModel(0, 1, parent)
|
||||
{
|
||||
setHeaderData(1, Qt::Horizontal, tr("Filters"));
|
||||
}
|
||||
|
||||
void DefaultFilterModel::addFilter(const QString & caption,
|
||||
const Filter & filter, const KIcon * icon)
|
||||
{
|
||||
QList<QStandardItem *> newRow;
|
||||
QStandardItem * item = new QStandardItem(caption);
|
||||
item->setData(qVariantFromValue<Filter>(filter));
|
||||
if (icon) item->setIcon(*icon);
|
||||
|
||||
newRow << item;
|
||||
appendRow(newRow);
|
||||
}
|
||||
|
||||
void DefaultFilterModel::addSeparator(const QString & caption)
|
||||
{
|
||||
QList<QStandardItem *> newRow;
|
||||
QStandardItem * item = new QStandardItem(caption);
|
||||
item->setEnabled(false);
|
||||
|
||||
newRow << item;
|
||||
appendRow(newRow);
|
||||
}
|
||||
|
||||
// DefaultItemFilterProxyModel
|
||||
|
||||
DefaultItemFilterProxyModel::DefaultItemFilterProxyModel(QObject * parent) :
|
||||
QSortFilterProxyModel(parent), m_innerModel(parent)
|
||||
{
|
||||
}
|
||||
|
||||
void DefaultItemFilterProxyModel::setSourceModel(
|
||||
QStandardItemModel * sourceModel)
|
||||
{
|
||||
m_innerModel.setSourceModel(sourceModel);
|
||||
QSortFilterProxyModel::setSourceModel(&m_innerModel);
|
||||
}
|
||||
|
||||
QStandardItemModel * DefaultItemFilterProxyModel::sourceModel() const
|
||||
{
|
||||
return m_innerModel.sourceModel();
|
||||
}
|
||||
|
||||
int DefaultItemFilterProxyModel::columnCount(const QModelIndex& index) const
|
||||
{
|
||||
Q_UNUSED(index);
|
||||
return 2;
|
||||
}
|
||||
|
||||
QVariant DefaultItemFilterProxyModel::data(const QModelIndex & index, int role) const
|
||||
{
|
||||
return m_innerModel.data(index, (index.column() == 1), role);
|
||||
}
|
||||
|
||||
bool DefaultItemFilterProxyModel::filterAcceptsRow(int sourceRow,
|
||||
const QModelIndex &sourceParent) const
|
||||
{
|
||||
QStandardItemModel * model = (QStandardItemModel *) sourceModel();
|
||||
|
||||
QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
|
||||
|
||||
AbstractItem * item = (AbstractItem *) model->itemFromIndex(index);
|
||||
//kDebug() << "ITEM " << (item ? "IS NOT " : "IS") << " NULL\n";
|
||||
|
||||
return (m_filter.first.isEmpty() || item->passesFiltering(m_filter))
|
||||
&&(m_searchPattern.isEmpty() || item->matches(m_searchPattern));
|
||||
}
|
||||
|
||||
bool DefaultItemFilterProxyModel::lessThan(const QModelIndex &left,
|
||||
const QModelIndex &right) const
|
||||
{
|
||||
return (sourceModel()->data(left).toString() < sourceModel()->data(right).toString());
|
||||
}
|
||||
|
||||
void DefaultItemFilterProxyModel::setSearch(const QString & pattern)
|
||||
{
|
||||
m_searchPattern = pattern;
|
||||
invalidateFilter();
|
||||
}
|
||||
|
||||
void DefaultItemFilterProxyModel::setFilter(const Filter & filter)
|
||||
{
|
||||
m_filter = filter;
|
||||
invalidateFilter();
|
||||
}
|
||||
|
||||
// DefaultItemFilterProxyModel::InnerProxyModel
|
||||
|
||||
DefaultItemFilterProxyModel::InnerProxyModel::InnerProxyModel(QObject * parent) :
|
||||
QAbstractItemModel(parent), m_sourceModel(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
Qt::ItemFlags DefaultItemFilterProxyModel::InnerProxyModel::flags(
|
||||
const QModelIndex & index) const
|
||||
{
|
||||
if (!m_sourceModel)
|
||||
return 0;
|
||||
return m_sourceModel->flags(index);
|
||||
}
|
||||
|
||||
QVariant DefaultItemFilterProxyModel::InnerProxyModel::data(
|
||||
const QModelIndex & index, bool favoriteColumn, int role) const
|
||||
{
|
||||
Q_UNUSED(favoriteColumn);
|
||||
return data(index, role);
|
||||
}
|
||||
|
||||
QVariant DefaultItemFilterProxyModel::InnerProxyModel::data(
|
||||
const QModelIndex & index, int role) const
|
||||
{
|
||||
if (!m_sourceModel)
|
||||
return QVariant();
|
||||
return m_sourceModel->data(index, role);
|
||||
}
|
||||
|
||||
QVariant DefaultItemFilterProxyModel::InnerProxyModel::headerData(int section,
|
||||
Qt::Orientation orientation, int role) const
|
||||
{
|
||||
Q_UNUSED(orientation);
|
||||
Q_UNUSED(role);
|
||||
return QVariant(section);
|
||||
}
|
||||
|
||||
int DefaultItemFilterProxyModel::InnerProxyModel::rowCount(
|
||||
const QModelIndex & parent) const
|
||||
{
|
||||
if (!m_sourceModel)
|
||||
return 0;
|
||||
return m_sourceModel->rowCount(parent);
|
||||
}
|
||||
|
||||
bool DefaultItemFilterProxyModel::InnerProxyModel::setData(
|
||||
const QModelIndex & index, const QVariant & value, int role)
|
||||
{
|
||||
if (!m_sourceModel)
|
||||
return false;
|
||||
return m_sourceModel->setData(index, value, role);
|
||||
}
|
||||
|
||||
bool DefaultItemFilterProxyModel::InnerProxyModel::setHeaderData(int section,
|
||||
Qt::Orientation orientation, const QVariant & value, int role)
|
||||
{
|
||||
Q_UNUSED(section);
|
||||
Q_UNUSED(value);
|
||||
Q_UNUSED(orientation);
|
||||
Q_UNUSED(role);
|
||||
return false;
|
||||
}
|
||||
|
||||
QModelIndex DefaultItemFilterProxyModel::InnerProxyModel::index(int row,
|
||||
int column, const QModelIndex & parent) const
|
||||
{
|
||||
Q_UNUSED(column);
|
||||
if (!m_sourceModel)
|
||||
return QModelIndex();
|
||||
return m_sourceModel->index(row, 0, parent);
|
||||
}
|
||||
|
||||
QModelIndex DefaultItemFilterProxyModel::InnerProxyModel::parent(
|
||||
const QModelIndex & index) const
|
||||
{
|
||||
if (!m_sourceModel)
|
||||
return QModelIndex();
|
||||
return m_sourceModel->parent(index);
|
||||
}
|
||||
|
||||
QMimeData * DefaultItemFilterProxyModel::InnerProxyModel::mimeData(
|
||||
const QModelIndexList & indexes) const
|
||||
{
|
||||
if (!m_sourceModel)
|
||||
return NULL;
|
||||
return m_sourceModel->mimeData(indexes);
|
||||
}
|
||||
|
||||
int DefaultItemFilterProxyModel::InnerProxyModel::columnCount(
|
||||
const QModelIndex& index) const
|
||||
{
|
||||
Q_UNUSED(index);
|
||||
return 2;
|
||||
}
|
||||
|
||||
void DefaultItemFilterProxyModel::InnerProxyModel::setSourceModel(
|
||||
QStandardItemModel * sourceModel)
|
||||
{
|
||||
m_sourceModel = sourceModel;
|
||||
}
|
||||
|
||||
QStandardItemModel * DefaultItemFilterProxyModel::InnerProxyModel::sourceModel() const
|
||||
{
|
||||
return m_sourceModel;
|
||||
}
|
||||
|
||||
// DefaultItemModel
|
||||
|
||||
DefaultItemModel::DefaultItemModel(QObject * parent) :
|
||||
QStandardItemModel(parent) {}
|
||||
}
|
172
appletbrowser/kcategorizeditemsviewmodels.h
Normal file
172
appletbrowser/kcategorizeditemsviewmodels.h
Normal file
@ -0,0 +1,172 @@
|
||||
/*
|
||||
* Copyright (C) 2007 Ivan Cukic <ivan.cukic+kde@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 (or,
|
||||
* at your option, any later version) as published by the Free Software
|
||||
* Foundation
|
||||
*
|
||||
* 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 Library 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 KCATEGORIZEDITEMSVIEWMODELS_H_
|
||||
#define KCATEGORIZEDITEMSVIEWMODELS_H_
|
||||
|
||||
#include <QtGui>
|
||||
#include <QtCore>
|
||||
#include <KIcon>
|
||||
#include <KDebug>
|
||||
namespace KCategorizedItemsViewModels {
|
||||
|
||||
typedef QPair<QString, QVariant> Filter;
|
||||
|
||||
/**
|
||||
* Abstract class that needs to be implemented and used with the ItemModel
|
||||
*/
|
||||
class AbstractItem : public QStandardItem
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Returns a localized string - name of the item
|
||||
*/
|
||||
virtual QString name() const;
|
||||
|
||||
/**
|
||||
* Returns a localized string - description of the item
|
||||
*/
|
||||
virtual QString description() const;
|
||||
|
||||
/**
|
||||
* Returns if the item is flagged as favorite
|
||||
* Default implementation checks if the item passes the Filter("favorite", "1") filter
|
||||
*/
|
||||
virtual bool isFavorite() const;
|
||||
|
||||
/**
|
||||
* Returns if the item contains string specified by pattern.
|
||||
* Default implementation checks whether name or description contain the
|
||||
* string (not needed to be exactly that string)
|
||||
*/
|
||||
virtual bool matches(const QString & pattern) const;
|
||||
|
||||
/**
|
||||
* sets the favorite flag for the item
|
||||
*/
|
||||
virtual void setFavorite(bool favorite) = 0;
|
||||
|
||||
/**
|
||||
* Returns if the item passes the filter specified
|
||||
*/
|
||||
virtual bool passesFiltering(const Filter & filter) const = 0;
|
||||
private:
|
||||
};
|
||||
|
||||
/**
|
||||
* The default implementation of the model containing filters
|
||||
*/
|
||||
class DefaultFilterModel : public QStandardItemModel
|
||||
{
|
||||
public:
|
||||
DefaultFilterModel(QObject * parent = 0);
|
||||
|
||||
/**
|
||||
* Adds a filter to the model
|
||||
* @param caption The localized string to be displayed as a name of the filter
|
||||
* @param filter The filter structure
|
||||
*/
|
||||
void addFilter(const QString & caption, const Filter & filter, const KIcon * icon = NULL);
|
||||
|
||||
/**
|
||||
* Adds a separator to the model
|
||||
* @param caption The localized string to be displayed as a name of the separator
|
||||
*/
|
||||
void addSeparator(const QString & caption);
|
||||
};
|
||||
|
||||
/**
|
||||
* Default filter proxy model.
|
||||
*/
|
||||
class DefaultItemFilterProxyModel : public QSortFilterProxyModel
|
||||
{
|
||||
public:
|
||||
DefaultItemFilterProxyModel(QObject * parent = 0);
|
||||
|
||||
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
|
||||
bool lessThan(const QModelIndex &left, const QModelIndex &right) const;
|
||||
|
||||
void setSearch(const QString & pattern);
|
||||
void setFilter(const Filter & filter);
|
||||
|
||||
void setSourceModel(QStandardItemModel * sourceModel);
|
||||
|
||||
QStandardItemModel * sourceModel() const;
|
||||
|
||||
int columnCount(const QModelIndex& index) const;
|
||||
|
||||
QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;
|
||||
|
||||
private:
|
||||
|
||||
class InnerProxyModel : public QAbstractItemModel
|
||||
{
|
||||
public:
|
||||
InnerProxyModel(QObject * parent = 0);
|
||||
|
||||
Qt::ItemFlags flags(const QModelIndex & index) const;
|
||||
|
||||
QVariant data(const QModelIndex & index, bool favoriteColumn,
|
||||
int role = Qt::DisplayRole) const;
|
||||
QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;
|
||||
bool setData(const QModelIndex & index, const QVariant & value,
|
||||
int role = Qt::EditRole);
|
||||
|
||||
QVariant headerData(int section, Qt::Orientation orientation,
|
||||
int role = Qt::DisplayRole) const;
|
||||
bool setHeaderData(int section, Qt::Orientation orientation,
|
||||
const QVariant & value, int role = Qt::EditRole);
|
||||
|
||||
int rowCount(const QModelIndex & parent = QModelIndex()) const;
|
||||
int columnCount(const QModelIndex& index) const;
|
||||
|
||||
|
||||
QModelIndex index(int row, int column,
|
||||
const QModelIndex & parent = QModelIndex()) const;
|
||||
QModelIndex parent(const QModelIndex & index) const;
|
||||
|
||||
QMimeData * mimeData(const QModelIndexList & indexes) const;
|
||||
|
||||
void setSourceModel(QStandardItemModel * sourceModel);
|
||||
QStandardItemModel * sourceModel() const;
|
||||
|
||||
private:
|
||||
QStandardItemModel * m_sourceModel;
|
||||
};
|
||||
|
||||
Filter m_filter;
|
||||
QString m_searchPattern;
|
||||
InnerProxyModel m_innerModel;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* The default implementation of the model containing items. It /is/ QStandardItemModel
|
||||
*/
|
||||
class DefaultItemModel : public QStandardItemModel
|
||||
{
|
||||
public:
|
||||
DefaultItemModel(QObject * parent = 0);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Q_DECLARE_METATYPE(KCategorizedItemsViewModels::Filter)
|
||||
|
||||
#endif /*KCATEGORIZEDITEMSVIEWMODELS_H_*/
|
45
appletbrowser/main.cpp
Normal file
45
appletbrowser/main.cpp
Normal file
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (C) 2007 Ivan Cukic <ivan.cukic+kde@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 (or,
|
||||
* at your option, any later version) as published by the Free Software
|
||||
* Foundation
|
||||
*
|
||||
* 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 Library 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 <kapplication.h>
|
||||
#include <kcmdlineargs.h>
|
||||
#include <kaboutdata.h>
|
||||
#include <KLocale>
|
||||
#include <KDebug>
|
||||
#include <QIcon>
|
||||
|
||||
#include <KAction>
|
||||
#include <KStandardAction>
|
||||
|
||||
#include "kcategorizeditemsview.h"
|
||||
#include "appletbrowserwindow.h"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
KLocale::setMainCatalog("konqueror");
|
||||
|
||||
KAboutData * aboutData = new KAboutData(QByteArray("testgui"), QByteArray(""), ki18n("TEST"), QByteArray("0"), ki18n("..."), KAboutData::License_GPL, KLocalizedString());
|
||||
KCmdLineArgs::init(argc, argv, aboutData);
|
||||
|
||||
KApplication test_Application;
|
||||
|
||||
(new AppletBrowserWindow())->show();
|
||||
|
||||
return test_Application.exec();
|
||||
}
|
145
appletbrowser/plasmaappletitemmodel.cpp
Normal file
145
appletbrowser/plasmaappletitemmodel.cpp
Normal file
@ -0,0 +1,145 @@
|
||||
/*
|
||||
* Copyright (C) 2007 Ivan Cukic <ivan.cukic+kde@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 (or,
|
||||
* at your option, any later version) as published by the Free Software
|
||||
* Foundation
|
||||
*
|
||||
* 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 Library 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 "plasmaappletitemmodel.h"
|
||||
|
||||
PlasmaAppletItem::PlasmaAppletItem(QObject * parent, QString name,
|
||||
QString pluginName, QString description, QString category, QIcon icon,
|
||||
FilterFlags flags) :
|
||||
QObject(parent)
|
||||
{
|
||||
QMap<QString, QVariant> attrs;
|
||||
attrs.insert("name", QVariant(name));
|
||||
attrs.insert("pluginName", QVariant(pluginName));
|
||||
attrs.insert("description", QVariant(description));
|
||||
attrs.insert("category", QVariant(category));
|
||||
attrs.insert("favorite", flags & Favorite ? true : false);
|
||||
attrs.insert("used", flags & Used ? true : false);
|
||||
attrs.insert("recommended", flags & Recommended ? true : false);
|
||||
setText(name + " - "+ description);
|
||||
setData(QVariant(attrs));
|
||||
setIcon(icon);
|
||||
}
|
||||
|
||||
PlasmaAppletItem::PlasmaAppletItem(QObject *parent, const KPluginInfo& info,
|
||||
FilterFlags flags) :
|
||||
QObject(parent)
|
||||
{
|
||||
QMap<QString, QVariant> attrs;
|
||||
attrs.insert("name", info.name());
|
||||
attrs.insert("pluginName", info.pluginName());
|
||||
attrs.insert("description", info.comment());
|
||||
attrs.insert("category", info.category());
|
||||
attrs.insert("favorite", flags & Favorite ? true : false);
|
||||
attrs.insert("used", flags & Used ? true : false);
|
||||
attrs.insert("recommended", flags & Recommended ? true : false);
|
||||
setText(info.name() + " - "+ info.category());
|
||||
setData(attrs);
|
||||
setIcon(KIcon(info.icon().isEmpty()?"application-x-plasma":info.icon()));
|
||||
|
||||
}
|
||||
|
||||
QString PlasmaAppletItem::name() const
|
||||
{
|
||||
return data().toMap()["name"].toString();
|
||||
}
|
||||
|
||||
QString PlasmaAppletItem::pluginName() const
|
||||
{
|
||||
return data().toMap()["pluginName"].toString();
|
||||
}
|
||||
|
||||
QString PlasmaAppletItem::description() const
|
||||
{
|
||||
return data().toMap()["description"].toString();
|
||||
}
|
||||
|
||||
void PlasmaAppletItem::setFavorite(bool favorite)
|
||||
{
|
||||
QMap<QString, QVariant> attrs = data().toMap();
|
||||
attrs.insert("favorite", favorite ? true : false);
|
||||
setData(QVariant(attrs));
|
||||
}
|
||||
|
||||
bool PlasmaAppletItem::passesFiltering(
|
||||
const KCategorizedItemsViewModels::Filter & filter) const
|
||||
{
|
||||
return data().toMap()[filter.first] == filter.second;
|
||||
}
|
||||
|
||||
PlasmaAppletItemModel::PlasmaAppletItemModel(QObject * parent) :
|
||||
KCategorizedItemsViewModels::DefaultItemModel(parent)
|
||||
{
|
||||
// some test items that do have FilterFlags as well as overly long text
|
||||
appendRow(new PlasmaAppletItem(this,
|
||||
i18n("This is a very long name for an applet, isn't it?"), "null",
|
||||
i18n("This is a Graphics applet whose description is even longer than it's title. And it was hard to achieve!"),
|
||||
QString("graph"),
|
||||
QIcon("/usr/share/icons/oxygen/64x64/apps/k3b.png"), PlasmaAppletItem::Used));
|
||||
appendRow(new PlasmaAppletItem(this,
|
||||
i18n("This is a very long name for another applet, isn't it?"), "null",
|
||||
i18n("This is a Graphics applet whose description is even longer than it's title. And it was hard to achieve!"),
|
||||
QString("graph"),
|
||||
QIcon("/usr/share/icons/oxygen/64x64/apps/kfind.png"), PlasmaAppletItem::Used | PlasmaAppletItem::Recommended));
|
||||
appendRow(new PlasmaAppletItem(this,
|
||||
i18n("This is my favorite item!"), "null",
|
||||
i18n("This is a Graphics applet whose description is even longer than it's title. And it was hard to achieve!"),
|
||||
QString("graph"),
|
||||
QIcon("/usr/share/icons/oxygen/64x64/apps/okular.png"), PlasmaAppletItem::Favorite | PlasmaAppletItem::Recommended));
|
||||
|
||||
//TODO: get recommended, favorit, used, etc out of knownApplets()
|
||||
foreach (const KPluginInfo& info, Plasma::Applet::knownApplets()) {
|
||||
appendRow(new PlasmaAppletItem(this, info));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
QStringList PlasmaAppletItemModel::mimeTypes() const
|
||||
{
|
||||
QStringList types;
|
||||
types << QLatin1String("text/x-plasmoidservicename");
|
||||
return types;
|
||||
}
|
||||
|
||||
QMimeData* PlasmaAppletItemModel::mimeData(const QModelIndexList & indexes) const
|
||||
{
|
||||
kDebug() << "GETTING MIME DATA\n";
|
||||
if (indexes.count() <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
QStringList types = mimeTypes();
|
||||
|
||||
if (types.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
QMimeData * data = new QMimeData();
|
||||
|
||||
QString format = types.at(0);
|
||||
|
||||
PlasmaAppletItem
|
||||
* selectedItem = (PlasmaAppletItem *) itemFromIndex(indexes[0]);
|
||||
QByteArray appletName(selectedItem->pluginName().toUtf8());
|
||||
|
||||
data->setData(format, appletName);
|
||||
|
||||
return data;
|
||||
}
|
69
appletbrowser/plasmaappletitemmodel.h
Normal file
69
appletbrowser/plasmaappletitemmodel.h
Normal file
@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright (C) 2007 Ivan Cukic <ivan.cukic+kde@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 (or,
|
||||
* at your option, any later version) as published by the Free Software
|
||||
* Foundation
|
||||
*
|
||||
* 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 Library 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 PLASMAAPPLETSMODEL_H_
|
||||
#define PLASMAAPPLETSMODEL_H_
|
||||
|
||||
#include <plasma/applet.h>
|
||||
#include <KPluginInfo>
|
||||
#include "kcategorizeditemsview.h"
|
||||
|
||||
/**
|
||||
* Implementation of the KCategorizedItemsViewModels::AbstractItem
|
||||
*/
|
||||
class PlasmaAppletItem : public KCategorizedItemsViewModels::AbstractItem,
|
||||
QObject
|
||||
{
|
||||
public:
|
||||
enum FilterFlag {NoFilter = 0,
|
||||
Favorite = 1,
|
||||
Used = 2,
|
||||
Recommended = 4};
|
||||
|
||||
Q_DECLARE_FLAGS(FilterFlags, FilterFlag)
|
||||
|
||||
PlasmaAppletItem(QObject * parent, QString name, QString pluginName,
|
||||
QString description, QString category, QIcon icon,
|
||||
FilterFlags flags = NoFilter);
|
||||
|
||||
PlasmaAppletItem(QObject *parent, const KPluginInfo& info,
|
||||
FilterFlags flags = NoFilter);
|
||||
|
||||
virtual QString name() const;
|
||||
QString pluginName() const;
|
||||
virtual QString description() const;
|
||||
virtual void setFavorite(bool favorite);
|
||||
virtual bool passesFiltering(
|
||||
const KCategorizedItemsViewModels::Filter & filter) const;
|
||||
};
|
||||
|
||||
class PlasmaAppletItemModel :
|
||||
public KCategorizedItemsViewModels::DefaultItemModel
|
||||
{
|
||||
public:
|
||||
PlasmaAppletItemModel(QObject * parent = 0);
|
||||
|
||||
QStringList mimeTypes() const;
|
||||
|
||||
QMimeData* mimeData(const QModelIndexList & indexes) const;
|
||||
};
|
||||
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(PlasmaAppletItem::FilterFlags)
|
||||
|
||||
#endif /*PLASMAAPPLETSMODEL_H_*/
|
@ -49,6 +49,8 @@
|
||||
#include "ksmserver_interface.h"
|
||||
#include "screensaver_interface.h"
|
||||
|
||||
#include "appletbrowser.h"
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
@ -84,9 +86,11 @@ public:
|
||||
QPixmap* bitmapBackground;
|
||||
QString wallpaperPath;
|
||||
QAction *engineExplorerAction;
|
||||
QAction *appletBrowserAction;
|
||||
QAction *runCommandAction;
|
||||
QAction *lockAction;
|
||||
QAction *logoutAction;
|
||||
AppletBrowser *appletBrowser;
|
||||
QSize size;
|
||||
int screen;
|
||||
bool immutable;
|
||||
@ -98,16 +102,19 @@ Containment::Containment(QGraphicsItem* parent,
|
||||
: Applet(parent, serviceId, containmentId),
|
||||
d(new Private)
|
||||
{
|
||||
d->appletBrowser = new AppletBrowser(this);
|
||||
}
|
||||
|
||||
Containment::Containment(QObject* parent, const QVariantList& args)
|
||||
: Applet(parent, args),
|
||||
d(new Private)
|
||||
{
|
||||
d->appletBrowser = new AppletBrowser(this);
|
||||
}
|
||||
|
||||
Containment::~Containment()
|
||||
{
|
||||
delete d->appletBrowser;
|
||||
delete d;
|
||||
}
|
||||
|
||||
@ -187,6 +194,11 @@ void Containment::launchExplorer()
|
||||
KRun::run("plasmaengineexplorer", KUrl::List(), 0);
|
||||
}
|
||||
|
||||
void Containment::launchAppletBrowser()
|
||||
{
|
||||
d->appletBrowser->show();
|
||||
}
|
||||
|
||||
void Containment::runCommand()
|
||||
{
|
||||
if (!KAuthorized::authorizeKAction("run_command")) {
|
||||
@ -239,15 +251,16 @@ QSizeF Containment::contentSizeHint() const
|
||||
QList<QAction*> Containment::contextActions()
|
||||
{
|
||||
//FIXME: several items here ... probably all junior jobs =)
|
||||
// - engineExplorerAction is going to go away, so the !d->engineExplorerAction below needs to
|
||||
// go
|
||||
// - pretty up the menu with separators
|
||||
// - should we offer "Switch User" here?
|
||||
|
||||
if (!d->engineExplorerAction) {
|
||||
if (!d->appletBrowserAction) {
|
||||
d->engineExplorerAction = new QAction(i18n("Engine Explorer"), this);
|
||||
connect(d->engineExplorerAction, SIGNAL(triggered(bool)), this, SLOT(launchExplorer()));
|
||||
|
||||
d->appletBrowserAction = new QAction(i18n("Add widget to desktop"), this);
|
||||
connect(d->appletBrowserAction, SIGNAL(triggered(bool)), this, SLOT(launchAppletBrowser()));
|
||||
|
||||
d->runCommandAction = new QAction(i18n("Run Command..."), this);
|
||||
connect(d->runCommandAction, SIGNAL(triggered(bool)), this, SLOT(runCommand()));
|
||||
|
||||
@ -263,6 +276,7 @@ QList<QAction*> Containment::contextActions()
|
||||
QList<QAction*> actions;
|
||||
|
||||
actions.append(d->engineExplorerAction);
|
||||
actions.append(d->appletBrowserAction);
|
||||
|
||||
if (KAuthorized::authorizeKAction("run_command")) {
|
||||
actions.append(d->runCommandAction);
|
||||
|
@ -229,6 +229,7 @@ class PLASMA_EXPORT Containment : public Applet
|
||||
*/
|
||||
void appletDestroyed(QObject*);
|
||||
void launchExplorer();
|
||||
void launchAppletBrowser();
|
||||
void runCommand();
|
||||
void lockScreen();
|
||||
void logout();
|
||||
|
Loading…
x
Reference in New Issue
Block a user