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

superkaramba

  • sources
  • kde-4.12
  • kdeutils
  • superkaramba
  • src
kwidgetlistbox.cpp
Go to the documentation of this file.
1 /*
2 * Copyright (C) 2005 Petri Damst� <petri.damsten@iki.fi>
3 *
4 * This file is part of SuperKaramba.
5 *
6 * SuperKaramba is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * SuperKaramba is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with SuperKaramba; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 ****************************************************************************/
20 #include "kwidgetlistbox.h"
21 
22 #include <QApplication>
23 
24 KWidgetListbox::KWidgetListbox(QWidget *parent)
25  : QTableWidget(parent)
26 {
27  setRowCount(0);
28  setColumnCount(1);
29 
30  horizontalHeader()->hide();
31  verticalHeader()->hide();
32 
33  setSelectionMode(QAbstractItemView::SingleSelection);
34 
35  connect(this, SIGNAL(cellClicked(int,int)),
36  this, SLOT(selectionChanged(int,int)));
37 
38  setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
39 
40  horizontalHeader()->setStretchLastSection(true);
41  setAlternatingRowColors(true);
42 }
43 
44 KWidgetListbox::~KWidgetListbox()
45 {
46  clear();
47 }
48 
49 void KWidgetListbox::clear()
50 {
51  QTableWidget::clear();
52 }
53 
54 int KWidgetListbox::insertItem(QWidget* item, int index)
55 {
56  int row = 0;
57  if (index == -1) {
58  row = rowCount();
59  setRowCount(row + 1);
60  } else
61  return -1;
62 
63  setRowHeight(row, item->height());
64  setCellWidget(row, 0, item);
65 
66  return row;
67 }
68 
69 void KWidgetListbox::setSelected(QWidget* item)
70 {
71  setSelected(index(item));
72 }
73 
74 void KWidgetListbox::selectionChanged(int row, int column)
75 {
76  setCurrentCell(row, column);
77  emit selected(row);
78 }
79 
80 void KWidgetListbox::removeItem(QWidget* item)
81 {
82  removeItem(index(item));
83 }
84 
85 void KWidgetListbox::removeItem(int index)
86 {
87  removeRow(index);
88 }
89 
90 void KWidgetListbox::setSelected(int index)
91 {
92  setCurrentCell(index, 0);
93 }
94 
95 int KWidgetListbox::selected() const
96 {
97  return currentRow();
98 }
99 
100 QWidget* KWidgetListbox::selectedItem() const
101 {
102  return item(selected());
103 }
104 
105 QWidget* KWidgetListbox::item(int index) const
106 {
107  return cellWidget(index, 0);
108 }
109 
110 int KWidgetListbox::index(QWidget* itm) const
111 {
112  for (int i = 0; i < rowCount(); ++i)
113  if (item(i) == itm)
114  return i;
115  return -1;
116 }
117 
118 void KWidgetListbox::showItems(show_callback func, void* data)
119 {
120  for (int i = 0; i < rowCount(); ++i) {
121  if (func == 0)
122  showRow(i);
123  else {
124  if (func(i, item(i), data))
125  showRow(i);
126  else
127  hideRow(i);
128  }
129  }
130 }
131 
132 void KWidgetListbox::showEvent(QShowEvent*)
133 {
134  repaint();
135 }
136 
137 void KWidgetListbox::mousePressEvent(QMouseEvent *event)
138 {
139  if(event->button() == Qt::LeftButton) {
140  m_dragStartPosition = event->pos();
141  }
142 
143  QTableWidget::mousePressEvent(event);
144 }
145 
146 void KWidgetListbox::mouseMoveEvent(QMouseEvent *event)
147 {
148  if(!(event->buttons() & Qt::LeftButton)) {
149  return;
150  }
151 
152  if ((event->pos() - m_dragStartPosition).manhattanLength() < QApplication::startDragDistance()) {
153  return;
154  }
155 
156  if (selected() <= 1) {
157  return;
158  }
159 
160  ThemeWidget *theme = qobject_cast<ThemeWidget*>(selectedItem());
161  QDrag *drag = new QDrag(this);
162  QMimeData *mimeData = new QMimeData;
163 
164 // mimeData->setData("superkaramba/theme", theme->path().toAscii());
165  drag->setMimeData(mimeData);
166  drag->setPixmap(theme->icon());
167 
168  drag->start(Qt::IgnoreAction);
169 
170  emit itemDropped(QCursor::pos(), theme);
171 }
172 
173 #include "kwidgetlistbox.moc"
QDrag
KWidgetListbox::mouseMoveEvent
virtual void mouseMoveEvent(QMouseEvent *event)
Definition: kwidgetlistbox.cpp:146
QTableWidget
KWidgetListbox::showEvent
virtual void showEvent(QShowEvent *e)
Definition: kwidgetlistbox.cpp:132
KWidgetListbox::selectionChanged
void selectionChanged(int row, int col)
Definition: kwidgetlistbox.cpp:74
QWidget
kwidgetlistbox.h
show_callback
bool(* show_callback)(int index, QWidget *widget, void *data)
Definition: kwidgetlistbox.h:34
KWidgetListbox::index
int index(QWidget *itm) const
Definition: kwidgetlistbox.cpp:110
KWidgetListbox::~KWidgetListbox
~KWidgetListbox()
Definition: kwidgetlistbox.cpp:44
KWidgetListbox::showItems
void showItems(show_callback func=0, void *data=0)
Definition: kwidgetlistbox.cpp:118
KWidgetListbox::mousePressEvent
virtual void mousePressEvent(QMouseEvent *event)
Definition: kwidgetlistbox.cpp:137
KWidgetListbox::selected
int selected() const
Definition: kwidgetlistbox.cpp:95
ThemeWidget::icon
QPixmap icon()
Definition: themewidget.cpp:113
KWidgetListbox::removeItem
void removeItem(QWidget *item)
Definition: kwidgetlistbox.cpp:80
KWidgetListbox::insertItem
int insertItem(QWidget *item, int index=-1)
Definition: kwidgetlistbox.cpp:54
ThemeWidget
Definition: themewidget.h:30
KWidgetListbox::setSelected
void setSelected(QWidget *item)
Definition: kwidgetlistbox.cpp:69
KWidgetListbox::clear
void clear()
Definition: kwidgetlistbox.cpp:49
KWidgetListbox::selectedItem
QWidget * selectedItem() const
Definition: kwidgetlistbox.cpp:100
KWidgetListbox::item
QWidget * item(int index) const
Definition: kwidgetlistbox.cpp:105
KWidgetListbox::itemDropped
void itemDropped(QPoint, ThemeWidget *)
KWidgetListbox::KWidgetListbox
KWidgetListbox(QWidget *parent=0)
Definition: kwidgetlistbox.cpp:24
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:07:20 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

superkaramba

Skip menu "superkaramba"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeutils API Reference

Skip menu "kdeutils API Reference"
  • ark
  • filelight
  • kcalc
  • kcharselect
  • kdf
  • kfloppy
  • kgpg
  • kremotecontrol
  • ktimer
  • kwallet
  • superkaramba
  • sweeper

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