1 | /* smplayer, GUI front-end for mplayer.
|
---|
2 | Copyright (C) 2006-2016 Ricardo Villalba <rvm@users.sourceforge.net>
|
---|
3 |
|
---|
4 | This program is free software; you can redistribute it and/or modify
|
---|
5 | it under the terms of the GNU General Public License as published by
|
---|
6 | the Free Software Foundation; either version 2 of the License, or
|
---|
7 | (at your option) any later version.
|
---|
8 |
|
---|
9 | This program is distributed in the hope that it will be useful,
|
---|
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
12 | GNU General Public License for more details.
|
---|
13 |
|
---|
14 | You should have received a copy of the GNU General Public License
|
---|
15 | along with this program; if not, write to the Free Software
|
---|
16 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
---|
17 | */
|
---|
18 |
|
---|
19 | #include "mytablewidget.h"
|
---|
20 | #include <QTableWidgetItem>
|
---|
21 |
|
---|
22 | #define BE_VERBOSE 0
|
---|
23 |
|
---|
24 | MyTableWidget::MyTableWidget( QWidget * parent ) : QTableWidget(parent)
|
---|
25 | {
|
---|
26 | }
|
---|
27 |
|
---|
28 | MyTableWidget::MyTableWidget( int rows, int columns, QWidget * parent )
|
---|
29 | : QTableWidget(rows, columns, parent)
|
---|
30 | {
|
---|
31 | }
|
---|
32 |
|
---|
33 | QTableWidgetItem * MyTableWidget::getItem(int row, int column, bool * existed ) {
|
---|
34 | #if BE_VERBOSE
|
---|
35 | qDebug("MyTableWidget::getItem: %d, %d", row, column);
|
---|
36 | #endif
|
---|
37 | QTableWidgetItem * i = item(row, column);
|
---|
38 | if (existed != 0) *existed = (i!=0); // Returns if the item already existed or not
|
---|
39 | if (i != 0) return i; else return createItem(column);
|
---|
40 | }
|
---|
41 |
|
---|
42 | QTableWidgetItem * MyTableWidget::createItem(int /*col*/) {
|
---|
43 | #if BE_VERBOSE
|
---|
44 | qDebug("MyTableWidget::createItem");
|
---|
45 | #endif
|
---|
46 | QTableWidgetItem * i = new QTableWidgetItem();
|
---|
47 | i->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled);
|
---|
48 | return i;
|
---|
49 | }
|
---|
50 |
|
---|
51 | void MyTableWidget::setText(int row, int column, const QString & text ) {
|
---|
52 | #if BE_VERBOSE
|
---|
53 | qDebug("MyTableWidget::setText: %d, %d", row, column);
|
---|
54 | #endif
|
---|
55 | bool existed;
|
---|
56 | QTableWidgetItem * i = getItem(row, column, &existed);
|
---|
57 | i->setText(text);
|
---|
58 | if (!existed) setItem(row, column, i);
|
---|
59 | }
|
---|
60 |
|
---|
61 | QString MyTableWidget::text(int row, int column) {
|
---|
62 | #if BE_VERBOSE
|
---|
63 | qDebug("MyTableWidget::text: %d, %d", row, column);
|
---|
64 | #endif
|
---|
65 | return getItem(row, column)->text();
|
---|
66 | }
|
---|
67 |
|
---|
68 | void MyTableWidget::setIcon(int row, int column, const QIcon & icon ) {
|
---|
69 | #if BE_VERBOSE
|
---|
70 | qDebug("MyTableWidget::setIcon %d, %d", row, column);
|
---|
71 | #endif
|
---|
72 | bool existed;
|
---|
73 | QTableWidgetItem * i = getItem(row, column, &existed);
|
---|
74 | i->setIcon(icon);
|
---|
75 | if (!existed) setItem(row, column, i);
|
---|
76 | }
|
---|
77 |
|
---|
78 | QIcon MyTableWidget::icon(int row, int column) {
|
---|
79 | return getItem(row, column)->icon();
|
---|
80 | }
|
---|
81 |
|
---|
82 | bool MyTableWidget::isSelected(int row, int column) {
|
---|
83 | return getItem(row, column)->isSelected();
|
---|
84 | }
|
---|
85 |
|
---|