25 using namespace Kontact;
27 #include <KontactInterface/Core>
28 #include <KontactInterface/Plugin>
33 #include <KStringHandler>
35 #include <QDragEnterEvent>
36 #include <QDragMoveEvent>
38 #include <QSortFilterProxyModel>
39 #include <QStringListModel>
40 #include <QStyledItemDelegate>
64 if ( !index.
isValid() && ( command & QItemSelectionModel::Clear ) ) {
74 if ( !selection.
count() && ( command & QItemSelectionModel::Clear ) ) {
85 PluginName = Qt::UserRole
106 flags &= ~Qt::ItemIsEditable;
109 if ( static_cast<KontactInterface::Plugin*>( index.
internalPointer() )->disabled() ) {
110 flags &= ~Qt::ItemIsEnabled;
111 flags &= ~Qt::ItemIsSelectable;
112 flags &= ~Qt::ItemIsDropEnabled;
114 flags |= Qt::ItemIsDropEnabled;
117 flags &= ~Qt::ItemIsDropEnabled;
127 if ( row < 0 || row >= pluginList.count() ) {
130 return createIndex( row, column, pluginList[row] );
139 if ( role == Qt::DisplayRole ) {
140 if ( !mNavigator->showText() ) {
143 return static_cast<KontactInterface::Plugin*
>( index.
internalPointer() )->title();
144 }
else if ( role == Qt::DecorationRole ) {
145 if ( !mNavigator->showIcons() ) {
148 return KIcon( static_cast<KontactInterface::Plugin*>( index.
internalPointer() )->icon() );
149 }
else if ( role == Qt::TextAlignmentRole ) {
150 return Qt::AlignCenter;
151 }
else if ( role == Qt::ToolTipRole ) {
152 if ( !mNavigator->showText() ) {
153 return static_cast<KontactInterface::Plugin*
>( index.
internalPointer() )->title();
156 }
else if ( role == PluginName ) {
157 return static_cast<KontactInterface::Plugin*
>( index.
internalPointer() )->identifier();
167 class SortFilterProxyModel
179 KontactInterface::Plugin *leftPlugin =
181 KontactInterface::Plugin *rightPlugin =
184 if ( leftPlugin->weight() == rightPlugin->weight() ) {
185 return KStringHandler::naturalCompare( leftPlugin->title(), rightPlugin->title() ) < 0;
188 return leftPlugin->weight() < rightPlugin->weight();
195 Delegate(
Navigator *parentNavigator = 0 )
208 optionCopy.decorationPosition = QStyleOptionViewItem::Top;
209 optionCopy.decorationSize =
QSize( mNavigator->iconSize(), mNavigator->iconSize() );
210 optionCopy.textElideMode = Qt::ElideNone;
221 optionCopy.decorationPosition = QStyleOptionViewItem::Top;
222 optionCopy.decorationSize =
223 mNavigator->showIcons() ?
QSize( mNavigator->iconSize(), mNavigator->iconSize() ) :
QSize();
224 optionCopy.textElideMode = Qt::ElideNone;
235 :
QListView( parent ), mSidePane( parent )
242 mIconSize = Prefs::self()->sidePaneIconSize();
243 mShowIcons = Prefs::self()->sidePaneShowIcons();
244 mShowText = Prefs::self()->sidePaneShowText();
248 mShowIconsAction =
new KAction( i18nc(
"@action:inmenu",
"Show Icons Only" ),
this );
249 mShowIconsAction->setCheckable(
true );
250 mShowIconsAction->setActionGroup( viewMode );
251 mShowIconsAction->setChecked( !mShowText && mShowIcons );
252 mShowIconsAction->setHelpText(
253 i18nc(
"@info:status",
254 "Show sidebar items with icons and without text" ) );
255 mShowIconsAction->setWhatsThis(
256 i18nc(
"@info:whatsthis",
257 "Choose this option if you want the sidebar items to have icons without text." ) );
258 connect( mShowIconsAction, SIGNAL(triggered(
bool)),
this, SLOT(slotActionTriggered(
bool)) );
260 mShowTextAction =
new KAction( i18nc(
"@action:inmenu",
"Show Text Only" ),
this );
261 mShowTextAction->setCheckable(
true );
262 mShowTextAction->setActionGroup( viewMode );
263 mShowTextAction->setChecked( mShowText && !mShowIcons );
264 mShowTextAction->setHelpText(
265 i18nc(
"@info:status",
266 "Show sidebar items with text and without icons" ) );
267 mShowTextAction->setWhatsThis(
268 i18nc(
"@info:whatsthis",
269 "Choose this option if you want the sidebar items to have text without icons." ) );
270 connect( mShowTextAction, SIGNAL(triggered(
bool)),
this, SLOT(slotActionTriggered(
bool)) );
272 mShowBothAction =
new KAction( i18nc(
"@action:inmenu",
"Show Icons && Text" ),
this );
273 mShowBothAction->setCheckable(
true );
274 mShowBothAction->setActionGroup( viewMode );
275 mShowBothAction->setChecked( mShowText && mShowIcons );
276 mShowBothAction->setHelpText(
277 i18nc(
"@info:status",
278 "Show sidebar items with icons and text" ) );
279 mShowBothAction->setWhatsThis(
280 i18nc(
"@info:whatsthis",
281 "Choose this option if you want the sidebar items to have icons and text." ) );
282 connect( mShowBothAction, SIGNAL(triggered(
bool)),
this, SLOT(slotActionTriggered(
bool)) );
284 KAction *sep =
new KAction(
this );
285 sep->setSeparator(
true );
289 mBigIconsAction =
new KAction( i18nc(
"@action:inmenu",
"Big Icons" ),
this );
290 mBigIconsAction->setCheckable(
true );
291 mBigIconsAction->setActionGroup( iconSize );
292 mBigIconsAction->setChecked( mIconSize == KIconLoader::SizeLarge );
293 mBigIconsAction->setHelpText(
294 i18nc(
"@info:status",
295 "Show large size sidebar icons" ) );
296 mBigIconsAction->setWhatsThis(
297 i18nc(
"@info:whatsthis",
298 "Choose this option if you want the sidebar icons to be extra big." ) );
299 connect( mBigIconsAction, SIGNAL(triggered(
bool)),
this, SLOT(slotActionTriggered(
bool)) );
301 mNormalIconsAction =
new KAction( i18nc(
"@action:inmenu",
"Normal Icons" ),
this );
302 mNormalIconsAction->setCheckable(
true );
303 mNormalIconsAction->setActionGroup( iconSize );
304 mNormalIconsAction->setChecked( mIconSize == KIconLoader::SizeMedium );
305 mNormalIconsAction->setHelpText(
306 i18nc(
"@info:status",
307 "Show normal size sidebar icons" ) );
308 mNormalIconsAction->setWhatsThis(
309 i18nc(
"@info:whatsthis",
310 "Choose this option if you want the sidebar icons to be normal size." ) );
311 connect( mNormalIconsAction, SIGNAL(triggered(
bool)),
this, SLOT(slotActionTriggered(
bool)) );
313 mSmallIconsAction =
new KAction( i18nc(
"@action:inmenu",
"Small Icons" ),
this );
314 mSmallIconsAction->setCheckable(
true );
315 mSmallIconsAction->setActionGroup( iconSize );
316 mSmallIconsAction->setChecked( mIconSize == KIconLoader::SizeSmallMedium );
317 mSmallIconsAction->setHelpText(
318 i18nc(
"@info:status",
319 "Show small size sidebar icons" ) );
320 mSmallIconsAction->setWhatsThis(
321 i18nc(
"@info:whatsthis",
322 "Choose this option if you want the sidebar icons to be extra small." ) );
323 connect( mSmallIconsAction, SIGNAL(triggered(
bool)),
this, SLOT(slotActionTriggered(
bool)) );
326 actionList << mShowIconsAction << mShowTextAction << mShowBothAction << sep
327 << mBigIconsAction << mNormalIconsAction << mSmallIconsAction;
334 mModel =
new Model(
this );
335 SortFilterProxyModel *sortFilterProxyModel =
new SortFilterProxyModel;
336 sortFilterProxyModel->setSourceModel( mModel );
356 foreach ( KontactInterface::Plugin *plugin, plugins_ ) {
357 if ( plugin->showInSideBar() ) {
358 pluginsToShow << plugin;
362 mModel->setPluginList( pluginsToShow );
364 mModel->removeRows( 0, mModel->rowCount() );
365 mModel->insertRows( 0, pluginsToShow.
count() );
368 if ( !currentPlugin.
isEmpty() ) {
375 const int numberOfRows(
model()->rowCount() );
376 for (
int i = 0; i < numberOfRows; ++i ) {
380 if ( plugin == pluginName ) {
395 const int numberOfRows(
model()->rowCount() );
396 for (
int i = 0; i < numberOfRows; ++i ) {
411 event->acceptProposedAction();
423 !( dropIndex.
model()->
flags( dropIndex ) & Qt::ItemIsEnabled ) ) {
424 event->setAccepted(
false );
429 KontactInterface::Plugin *plugin =
430 static_cast<KontactInterface::Plugin*
>( sourceIndex.
internalPointer() );
431 if ( !plugin->canDecodeMimeData( event->
mimeData() ) ) {
432 event->setAccepted(
false );
437 event->acceptProposedAction();
453 KontactInterface::Plugin *plugin =
454 static_cast<KontactInterface::Plugin*
>( sourceIndex.
internalPointer() );
455 plugin->processDropEvent( event );
467 void Navigator::slotCurrentChanged(
const QModelIndex ¤t )
470 !( current.
model()->
flags( current ) & Qt::ItemIsEnabled ) ) {
480 void Navigator::slotActionTriggered(
bool checked )
484 if (
object == mShowIconsAction ) {
485 mShowIcons = checked;
486 mShowText = !checked;
487 }
else if (
object == mShowTextAction ) {
488 mShowIcons = !checked;
490 }
else if (
object == mShowBothAction ) {
491 mShowIcons = checked;
493 }
else if (
object == mBigIconsAction ) {
494 mIconSize = KIconLoader::SizeLarge;
495 }
else if (
object == mNormalIconsAction ) {
496 mIconSize = KIconLoader::SizeMedium;
497 }
else if (
object == mSmallIconsAction ) {
498 mIconSize = KIconLoader::SizeSmallMedium;
501 Prefs::self()->setSidePaneIconSize( mIconSize );
502 Prefs::self()->setSidePaneShowIcons( mShowIcons );
503 Prefs::self()->setSidePaneShowText( mShowText );
510 void Navigator::updateNavigatorSize()
521 connect( mNavigator, SIGNAL(pluginActivated(KontactInterface::Plugin*)),
virtual void showEvent(QShowEvent *event)
virtual void setSelectionModel(QItemSelectionModel *selectionModel)
IconSidePane(KontactInterface::Core *core, QWidget *parent)
ViewMode viewMode() const
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const =0
const QMimeData * mimeData() const
virtual void sort(int column, Qt::SortOrder order)
void setCurrentPlugin(const QString &plugin)
virtual void dragMoveEvent(QDragMoveEvent *event)
QItemSelectionModel * selectionModel() const
QRect contentsRect() const
Qt::DropAction proposedAction() const
virtual Qt::ItemFlags flags(const QModelIndex &index) const
virtual void setModel(QAbstractItemModel *model)
const QPoint & pos() const
void setDragDropMode(DragDropMode behavior)
void pluginSelected(KontactInterface::Plugin *)
void resizeEvent(QResizeEvent *event)
virtual QModelIndex parent(const QModelIndex &child) const
void pluginActivated(KontactInterface::Plugin *plugin)
int count(const T &value) const
virtual QVariant data(const QModelIndex &index, int role) const
virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
virtual void dropEvent(QDropEvent *event)
virtual void select(const QModelIndex &index, QFlags< QItemSelectionModel::SelectionFlag > command)
void setItemDelegate(QAbstractItemDelegate *delegate)
virtual QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
void setDynamicSortFilter(bool enable)
void * internalPointer() const
virtual QVariant data(const QModelIndex &index, int role) const =0
QSize sizeHintForIndex(const QModelIndex &index) const
void setCurrentPlugin(const QString &plugin)
QModelIndex createIndex(int row, int column, void *ptr) const
virtual void updatePlugins()
virtual QSize sizeHint() const
virtual QModelIndex indexAt(const QPoint &p) const
const QAbstractItemModel * model() const
Navigator(SidePaneBase *parent=0)
virtual Qt::ItemFlags flags(const QModelIndex &index) const
void setCurrentIndex(const QModelIndex &index, QFlags< QItemSelectionModel::SelectionFlag > command)
void updatePlugins(QList< KontactInterface::Plugin * > plugins)
QAbstractItemModel * model() const
QModelIndex currentIndex() const
KontactInterface::Core * core() const
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
virtual void currentChanged(const QModelIndex ¤t, const QModelIndex &previous)
virtual void dragEnterEvent(QDragEnterEvent *event)
void setDropIndicatorShown(bool enable)