• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdenetwork API Reference
  • KDE Home
  • Contact Us
 

kopete/kopete

  • sources
  • kde-4.14
  • kdenetwork
  • kopete
  • kopete
  • config
  • appearance
tooltipeditdialog.cpp
Go to the documentation of this file.
1 /*
2  tooltipeditdialog.cpp - Kopete Tooltip Editor
3 
4  Copyright (c) 2004 by Stefan Gehn <metz@gehn.net>
5 
6  Kopete (c) 2004 by the Kopete developers <kopete-devel@kde.org>
7 
8  *************************************************************************
9  * *
10  * This program is free software; you can redistribute it and/or modify *
11  * it under the terms of the GNU General Public License as published by *
12  * the Free Software Foundation; either version 2 of the License, or *
13  * (at your option) any later version. *
14  * *
15  *************************************************************************
16 */
17 
18 #include "tooltipeditdialog.h"
19 
20 #include "kopeteproperty.h"
21 #include "kopeteglobal.h"
22 #include "kopeteappearancesettings.h"
23 
24 #include <QStringList>
25 #include <QApplication>
26 #include <QToolButton>
27 #include <QStandardItemModel>
28 #include <QSortFilterProxyModel>
29 
30 #include <kiconloader.h>
31 #include <klocale.h>
32 
33 TooltipEditDialog::TooltipEditDialog(QWidget *parent)
34  : KDialog(parent)
35 {
36  setCaption( i18n("Tooltip Editor") );
37  setButtons( KDialog::Ok | KDialog::Cancel );
38  setDefaultButton(KDialog::Ok);
39  showButtonSeparator(true);
40 
41  mMainWidget = new QWidget(this);
42  mMainWidget->setObjectName("TooltipEditDialog::mMainWidget");
43  setupUi(mMainWidget);
44 
45  setMainWidget(mMainWidget);
46 
47  /*
48  * Fill the model with the appropriates entries (pairs label/internal string)
49  */
50  mUnusedEntries = new QStandardItemModel(this);
51  mUsedEntries = new QStandardItemModel(this);
52 
53  const Kopete::PropertyTmpl::Map propmap(
54  Kopete::Global::Properties::self()->templateMap());
55  const QStringList usedKeys = Kopete::AppearanceSettings::self()->toolTipContents();
56 
57  // first fill the "used" list
58  foreach(const QString &usedProp, usedKeys)
59  {
60  if(propmap.contains(usedProp) && !propmap[usedProp].isPrivate())
61  {
62  QStandardItem *item = new QStandardItem( propmap[usedProp].label() );
63  item->setData( usedProp );
64  mUsedEntries->appendRow( item );
65  }
66  }
67 
68  // then iterate over all known properties and insert the remaining ones
69  // into the "unused" list
70  Kopete::PropertyTmpl::Map::ConstIterator it;
71  for(it = propmap.begin(); it != propmap.end(); ++it)
72  {
73  if((usedKeys.contains(it.key())==0) && (!it.value().isPrivate()))
74  {
75  QStandardItem *item = new QStandardItem( it.value().label() );
76  item->setData( it.key() );
77  mUnusedEntries->appendRow( item );
78  }
79  }
80 
81  // We use a proxy for mUnusedEntries because it needs to be alphabetically sorted
82  QSortFilterProxyModel *proxyModel = new QSortFilterProxyModel( this );
83  proxyModel->setSourceModel( mUnusedEntries );
84  proxyModel->sort( 0, Qt::AscendingOrder );
85  unusedItemsListView->setModel( proxyModel );
86  usedItemsListView->setModel( mUsedEntries );
87 
88  /*
89  * Ui setup
90  */
91  connect(unusedItemsListView->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
92  this, SLOT(slotUnusedSelected(QItemSelection)));
93  connect(usedItemsListView->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
94  this, SLOT(slotUsedSelected(QItemSelection)));
95  connect(unusedItemsListView, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(slotAddButton()));
96  connect(usedItemsListView, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(slotRemoveButton()));
97 
98  tbUp->setIcon(KIcon("go-up"));
99  tbUp->setEnabled(false);
100  tbUp->setAutoRepeat(true);
101  connect(tbUp, SIGNAL(clicked()), SLOT(slotUpButton()));
102 
103  tbDown->setIcon(KIcon("go-down"));
104  tbDown->setEnabled(false);
105  tbDown->setAutoRepeat(true);
106  connect(tbDown, SIGNAL(clicked()), SLOT(slotDownButton()));
107 
108  KIcon left = KIcon("go-previous");
109  KIcon right = KIcon("go-next");
110 
111  tbAdd->setIcon(QApplication::isRightToLeft() ? left : right);
112  tbAdd->setEnabled(false);
113  connect(tbAdd, SIGNAL(clicked()), SLOT(slotAddButton()));
114 
115  tbRemove->setIcon(QApplication::isRightToLeft() ? right : left);
116  tbRemove->setEnabled(false);
117  connect(tbRemove, SIGNAL(clicked()), SLOT(slotRemoveButton()));
118 
119  connect(this, SIGNAL(okClicked()), this, SLOT(slotOkClicked()));
120 
121  resize(QSize(450, 450));
122 }
123 
124 void TooltipEditDialog::slotOkClicked()
125 {
126  QStringList oldList = Kopete::AppearanceSettings::self()->toolTipContents();
127  QStringList newList;
128 
129  QString keyname;
130 
131  int max = mUsedEntries->rowCount( );
132  for ( int i=0; i < max; i++ )
133  {
134  QStandardItem *item = mUsedEntries->item( i, 0 );
135  keyname = item->data().value<QString>();
136  newList += keyname;
137  // kDebug(14000) <<
138  // "Adding key '" << keyname << "' to tooltip list" << endl;
139  }
140 
141  if(oldList != newList)
142  {
143  Kopete::AppearanceSettings::self()->setToolTipContents(newList);
144  emit changed(true);
145  kDebug(14000) << "tooltip fields changed, emitting changed()";
146  }
147 }
148 
149 
150 void TooltipEditDialog::slotUnusedSelected(const QItemSelection& selected)
151 {
152  tbAdd->setEnabled(selected.indexes().count());
153 }
154 
155 void TooltipEditDialog::slotUsedSelected(const QItemSelection& selected)
156 {
157  tbRemove->setEnabled( selected.indexes().count() );
158  tbUp->setEnabled( selected.indexes().count() );
159  tbDown->setEnabled( selected.indexes().count() );
160 
161  if ( !selected.indexes().count() )
162  return;
163 
164  // Disable Up button if we are at the top, disable Down one if we are at bottom
165  if ( selected.indexes().first().row() == 0 )
166  tbUp->setEnabled( false );
167  else
168  tbUp->setEnabled( true );
169 
170  if ( selected.indexes().last().row() == mUsedEntries->rowCount() - 1 )
171  tbDown->setEnabled( false );
172  else
173  tbDown->setEnabled( true );
174 }
175 
176 void TooltipEditDialog::slotUpButton()
177 {
178  QModelIndexList indexList = usedItemsListView->selectionModel()->selectedIndexes();
179  usedItemsListView->selectionModel()->clear();
180 
181  foreach( const QModelIndex &index, indexList )
182  {
183  int row = index.row();
184 
185  if ( row - 1 < 0 )
186  return;
187 
188  // Move it up
189  mUsedEntries->insertRow( row - 1, mUsedEntries->takeRow( row ) );
190 
191  // Keep the element selected
192  usedItemsListView->selectionModel()->select( mUsedEntries->index( row - 1, 0 ) , QItemSelectionModel::Select );
193  usedItemsListView->scrollTo( mUsedEntries->index( row - 1, 0 ) );
194 
195  // Check for the up and down buttons
196  if ( row - 1 == 0 )
197  tbUp->setEnabled( false );
198  tbDown->setEnabled( true );
199  }
200 }
201 
202 void TooltipEditDialog::slotDownButton()
203 {
204  QModelIndexList indexList = usedItemsListView->selectionModel()->selectedIndexes();
205  usedItemsListView->selectionModel()->clear();
206 
207  foreach( const QModelIndex &index, indexList ) {
208  int row = index.row();
209 
210  if ( row + 1 > mUsedEntries->rowCount() )
211  return;
212 
213  // Move it down
214  mUsedEntries->insertRow( row + 1, mUsedEntries->takeRow( row ) );
215 
216  // Keep it selected
217  usedItemsListView->selectionModel()->select( mUsedEntries->index( row + 1, 0 ) , QItemSelectionModel::Select );
218  usedItemsListView->scrollTo( mUsedEntries->index( row + 1, 0 ) );
219 
220 
221  // Check for the up and down buttons
222  if ( row + 1 == mUsedEntries->rowCount() - 1 )
223  tbDown->setEnabled( false );
224  tbUp->setEnabled( true );
225  }
226 }
227 
228 void TooltipEditDialog::slotAddButton()
229 {
230  QModelIndexList indexList = unusedItemsListView->selectionModel()->selectedIndexes();
231 
232  foreach( const QModelIndex &index_, indexList )
233  {
234  QModelIndex index = static_cast<QSortFilterProxyModel*>( unusedItemsListView->model() )->mapToSource( index_ );
235 
236  // We insert it after the last selected one if there is a selection,
237  // at the end else.
238  QModelIndex insertAfter;
239  if ( !usedItemsListView->selectionModel()->selectedIndexes().isEmpty() )
240  insertAfter = usedItemsListView->selectionModel()->selectedIndexes().last();
241  else
242  insertAfter = mUsedEntries->index( mUsedEntries->rowCount() - 1, 0 );
243 
244  // Move the row from the unused items list to the used items one.
245  mUsedEntries->insertRow( insertAfter.row() + 1, mUnusedEntries->takeRow( index.row() ) );
246 
247  // Make the newly inserted item current
248  QModelIndex newIndex = mUsedEntries->index( insertAfter.row() + 1, 0 );
249  usedItemsListView->setCurrentIndex( newIndex );
250  }
251 }
252 
253 void TooltipEditDialog::slotRemoveButton()
254 {
255  QModelIndexList indexList = usedItemsListView->selectionModel()->selectedIndexes();
256 
257  foreach( const QModelIndex &index, indexList )
258  {
259  int row = index.row();
260 
261 
262  mUnusedEntries->insertRow( 0, mUsedEntries->takeRow( index.row() ) );
263 
264  // Move selection
265  if ( row > 0 )
266  usedItemsListView->selectionModel()->select( mUsedEntries->index( row - 1, 0 ), QItemSelectionModel::Select );
267  else
268  usedItemsListView->selectionModel()->select( mUsedEntries->index( row, 0 ), QItemSelectionModel::Select );
269 
270  }
271 }
272 
273 #include "tooltipeditdialog.moc"
QItemSelection::indexes
QModelIndexList indexes() const
QStandardItemModel::index
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const
QModelIndex
QStandardItemModel
QWidget
QApplication::isRightToLeft
bool isRightToLeft()
QSortFilterProxyModel::sort
virtual void sort(int column, Qt::SortOrder order)
TooltipEditDialog::TooltipEditDialog
TooltipEditDialog(QWidget *parent=0)
Definition: tooltipeditdialog.cpp:33
QSortFilterProxyModel::setSourceModel
virtual void setSourceModel(QAbstractItemModel *sourceModel)
QStringList::contains
bool contains(const QString &str, Qt::CaseSensitivity cs) const
QVariant::value
T value() const
KDialog
QStandardItem::setData
virtual void setData(const QVariant &value, int role)
TooltipEditDialog::changed
void changed(bool)
QObject::setObjectName
void setObjectName(const QString &name)
QModelIndex::row
int row() const
QString
QStandardItemModel::insertRow
void insertRow(int row, const QList< QStandardItem * > &items)
QStringList
QStandardItemModel::item
QStandardItem * item(int row, int column) const
QSize
QSortFilterProxyModel
QStandardItemModel::takeRow
QList< QStandardItem * > takeRow(int row)
QItemSelection
tooltipeditdialog.h
QStandardItemModel::rowCount
virtual int rowCount(const QModelIndex &parent) const
QStandardItem
QStandardItemModel::appendRow
void appendRow(const QList< QStandardItem * > &items)
QStandardItem::data
virtual QVariant data(int role) const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:29:08 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kopete/kopete

Skip menu "kopete/kopete"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdenetwork API Reference

Skip menu "kdenetwork API Reference"
  • kget
  • kopete
  •   kopete
  •   libkopete
  • krdc
  • krfb

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal