1
/****************************************************************************
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
5
** This file is part of the designer application of the Qt Toolkit.
7
** This file may be distributed under the terms of the Q Public License
8
** as defined by Trolltech AS of Norway and appearing in the file
9
** LICENSE.QPL included in the packaging of this file.
11
** This file may be distributed and/or modified under the terms of the
12
** GNU General Public License version 2 as published by the Free Software
13
** Foundation and appearing in the file LICENSE.GPL included in the
14
** packaging of this file.
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
17
** information about Qt Commercial License Agreements.
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
21
** Contact info@trolltech.com if any conditions of this licensing are
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27
****************************************************************************/
29
#include "listwidgeteditor.h"
30
#include <findicondialog_p.h>
31
#include <iconloader_p.h>
33
#include <QtDesigner/QtDesigner>
34
#include <QtGui/QComboBox>
35
#include <QtCore/QDir>
36
#include <QtCore/qdebug.h>
38
using namespace qdesigner_internal;
40
ListWidgetEditor::ListWidgetEditor(QDesignerFormWindowInterface *form, QWidget *parent)
45
ui.deleteButton->setIcon(createIconSet(QString::fromUtf8("editdelete.png")));
46
ui.deleteButton->setEnabled(false);
49
ListWidgetEditor::~ListWidgetEditor()
53
void ListWidgetEditor::fillContentsFromListWidget(QListWidget *listWidget)
55
for (int i=0; i<listWidget->count(); ++i) {
56
QListWidgetItem *item = listWidget->item(i);
57
ui.listWidget->addItem(item->clone());
60
ui.listWidget->setCurrentRow(ui.listWidget->count() - 1);
63
void ListWidgetEditor::fillContentsFromComboBox(QComboBox *comboBox)
65
for (int i=0; i<comboBox->count(); ++i) {
66
QListWidgetItem *item = new QListWidgetItem();
67
item->setText(comboBox->itemText(i));
68
item->setIcon(comboBox->itemIcon(i));
69
ui.listWidget->addItem(item);
72
ui.listWidget->setCurrentRow(ui.listWidget->count() - 1);
75
void ListWidgetEditor::on_newItemButton_clicked()
77
int row = ui.listWidget->currentRow() + 1;
79
if (row < ui.listWidget->count()) {
80
ui.listWidget->insertItem(row, tr("New Item"));
82
ui.listWidget->addItem(tr("New Item"));
83
ui.listWidget->setCurrentRow(ui.listWidget->count() - 1);
84
row = ui.listWidget->count() - 1;
87
ui.listWidget->setCurrentRow(row);
90
void ListWidgetEditor::on_deleteItemButton_clicked()
92
int row = ui.listWidget->currentRow();
95
delete ui.listWidget->takeItem(row);
97
if (row < ui.listWidget->count())
98
ui.listWidget->setCurrentRow(row);
101
void ListWidgetEditor::on_moveItemUpButton_clicked()
103
int row = ui.listWidget->currentRow();
105
return; // nothing to do
107
ui.listWidget->insertItem(row - 1, ui.listWidget->takeItem(row));
108
ui.listWidget->setCurrentRow(row - 1);
111
void ListWidgetEditor::on_moveItemDownButton_clicked()
113
int row = ui.listWidget->currentRow();
114
if (row == -1 || row == ui.listWidget->count() - 1)
115
return; // nothing to do
117
ui.listWidget->insertItem(row + 1, ui.listWidget->takeItem(row));
118
ui.listWidget->setCurrentRow(row + 1);
121
void ListWidgetEditor::on_listWidget_currentRowChanged(int currentRow)
126
if (currentRow != -1) {
127
QListWidgetItem *item = ui.listWidget->item(currentRow);
132
ui.itemTextLineEdit->setText(text);
133
ui.previewButton->setIcon(icon);
134
ui.deleteButton->setEnabled(!icon.isNull());
135
ui.itemTextLineEdit->selectAll();
136
ui.itemTextLineEdit->setFocus();
139
void ListWidgetEditor::on_itemTextLineEdit_textChanged(const QString &text)
141
int currentRow = ui.listWidget->currentRow();
142
if (currentRow != -1) {
143
QListWidgetItem *item = ui.listWidget->item(currentRow);
148
void ListWidgetEditor::on_deleteButton_clicked()
150
int currentRow = ui.listWidget->currentRow();
151
if (currentRow == -1)
153
QListWidgetItem *item = ui.listWidget->item(currentRow);
155
item->setIcon(QIcon());
156
ui.previewButton->setIcon(QIcon());
157
ui.deleteButton->setEnabled(false);
160
void ListWidgetEditor::on_previewButton_clicked()
162
int currentRow = ui.listWidget->currentRow();
163
if (currentRow == -1)
165
QListWidgetItem *item = ui.listWidget->item(currentRow);
167
FindIconDialog dialog(m_form, 0);
171
QIcon icon = item->icon();
173
file_path = m_form->absoluteDir().absolutePath();
175
file_path = m_form->core()->iconCache()->iconToFilePath(icon);
176
qrc_path = m_form->core()->iconCache()->iconToQrcPath(icon);
179
dialog.setPaths(qrc_path, file_path);
181
file_path = dialog.filePath();
182
qrc_path = dialog.qrcPath();
183
if (!file_path.isEmpty()) {
184
icon = m_form->core()->iconCache()->nameToIcon(file_path, qrc_path);
186
ui.previewButton->setIcon(icon);
187
ui.deleteButton->setEnabled(!icon.isNull());
192
int ListWidgetEditor::count() const
194
return ui.listWidget->count();
197
QIcon ListWidgetEditor::icon(int row) const
199
return ui.listWidget->item(row)->icon();
202
QString ListWidgetEditor::text(int row) const
204
return ui.listWidget->item(row)->text();