~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to tools/designer/src/components/taskmenu/listwidgeteditor.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
 
4
**
 
5
** This file is part of the designer application of the Qt Toolkit.
 
6
**
 
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.
 
10
**
 
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.
 
15
**
 
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.
 
20
**
 
21
** Contact info@trolltech.com if any conditions of this licensing are
 
22
** not clear to you.
 
23
**
 
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.
 
26
**
 
27
****************************************************************************/
 
28
 
 
29
#include "listwidgeteditor.h"
 
30
#include <findicondialog_p.h>
 
31
#include <iconloader_p.h>
 
32
 
 
33
#include <QtDesigner/QtDesigner>
 
34
#include <QtGui/QComboBox>
 
35
#include <QtCore/QDir>
 
36
#include <QtCore/qdebug.h>
 
37
 
 
38
using namespace qdesigner_internal;
 
39
 
 
40
ListWidgetEditor::ListWidgetEditor(QDesignerFormWindowInterface *form, QWidget *parent)
 
41
    : QDialog(parent)
 
42
{
 
43
    ui.setupUi(this);
 
44
    m_form = form;
 
45
    ui.deleteButton->setIcon(createIconSet(QString::fromUtf8("editdelete.png")));
 
46
    ui.deleteButton->setEnabled(false);
 
47
}
 
48
 
 
49
ListWidgetEditor::~ListWidgetEditor()
 
50
{
 
51
}
 
52
 
 
53
void ListWidgetEditor::fillContentsFromListWidget(QListWidget *listWidget)
 
54
{
 
55
    for (int i=0; i<listWidget->count(); ++i) {
 
56
        QListWidgetItem *item = listWidget->item(i);
 
57
        ui.listWidget->addItem(item->clone());
 
58
    }
 
59
 
 
60
    ui.listWidget->setCurrentRow(ui.listWidget->count() - 1);
 
61
}
 
62
 
 
63
void ListWidgetEditor::fillContentsFromComboBox(QComboBox *comboBox)
 
64
{
 
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);
 
70
    }
 
71
 
 
72
    ui.listWidget->setCurrentRow(ui.listWidget->count() - 1);
 
73
}
 
74
 
 
75
void ListWidgetEditor::on_newItemButton_clicked()
 
76
{
 
77
    int row = ui.listWidget->currentRow() + 1;
 
78
 
 
79
    if (row < ui.listWidget->count()) {
 
80
        ui.listWidget->insertItem(row, tr("New Item"));
 
81
    } else {
 
82
        ui.listWidget->addItem(tr("New Item"));
 
83
        ui.listWidget->setCurrentRow(ui.listWidget->count() - 1);
 
84
        row = ui.listWidget->count() - 1;
 
85
    }
 
86
 
 
87
    ui.listWidget->setCurrentRow(row);
 
88
}
 
89
 
 
90
void ListWidgetEditor::on_deleteItemButton_clicked()
 
91
{
 
92
    int row = ui.listWidget->currentRow();
 
93
 
 
94
    if (row != -1)
 
95
        delete ui.listWidget->takeItem(row);
 
96
 
 
97
    if (row < ui.listWidget->count())
 
98
        ui.listWidget->setCurrentRow(row);
 
99
}
 
100
 
 
101
void ListWidgetEditor::on_moveItemUpButton_clicked()
 
102
{
 
103
    int row = ui.listWidget->currentRow();
 
104
    if (row <= 0)
 
105
        return; // nothing to do
 
106
 
 
107
    ui.listWidget->insertItem(row - 1, ui.listWidget->takeItem(row));
 
108
    ui.listWidget->setCurrentRow(row - 1);
 
109
}
 
110
 
 
111
void ListWidgetEditor::on_moveItemDownButton_clicked()
 
112
{
 
113
    int row = ui.listWidget->currentRow();
 
114
    if (row == -1 || row == ui.listWidget->count() - 1)
 
115
        return; // nothing to do
 
116
 
 
117
    ui.listWidget->insertItem(row + 1, ui.listWidget->takeItem(row));
 
118
    ui.listWidget->setCurrentRow(row + 1);
 
119
}
 
120
 
 
121
void ListWidgetEditor::on_listWidget_currentRowChanged(int currentRow)
 
122
{
 
123
    QString text;
 
124
    QIcon icon;
 
125
 
 
126
    if (currentRow != -1) {
 
127
        QListWidgetItem *item = ui.listWidget->item(currentRow);
 
128
        text = item->text();
 
129
        icon = item->icon();
 
130
    }
 
131
 
 
132
    ui.itemTextLineEdit->setText(text);
 
133
    ui.previewButton->setIcon(icon);
 
134
    ui.deleteButton->setEnabled(!icon.isNull());
 
135
    ui.itemTextLineEdit->selectAll();
 
136
    ui.itemTextLineEdit->setFocus();
 
137
}
 
138
 
 
139
void ListWidgetEditor::on_itemTextLineEdit_textChanged(const QString &text)
 
140
{
 
141
    int currentRow = ui.listWidget->currentRow();
 
142
    if (currentRow != -1) {
 
143
        QListWidgetItem *item = ui.listWidget->item(currentRow);
 
144
        item->setText(text);
 
145
    }
 
146
}
 
147
 
 
148
void ListWidgetEditor::on_deleteButton_clicked()
 
149
{
 
150
    int currentRow = ui.listWidget->currentRow();
 
151
    if (currentRow == -1)
 
152
        return;
 
153
    QListWidgetItem *item = ui.listWidget->item(currentRow);
 
154
 
 
155
    item->setIcon(QIcon());
 
156
    ui.previewButton->setIcon(QIcon());
 
157
    ui.deleteButton->setEnabled(false);
 
158
}
 
159
 
 
160
void ListWidgetEditor::on_previewButton_clicked()
 
161
{
 
162
    int currentRow = ui.listWidget->currentRow();
 
163
    if (currentRow == -1)
 
164
        return;
 
165
    QListWidgetItem *item = ui.listWidget->item(currentRow);
 
166
 
 
167
    FindIconDialog dialog(m_form, 0);
 
168
    QString file_path;
 
169
    QString qrc_path;
 
170
 
 
171
    QIcon icon = item->icon();
 
172
    if (icon.isNull()) {
 
173
        file_path = m_form->absoluteDir().absolutePath();
 
174
    } else {
 
175
        file_path = m_form->core()->iconCache()->iconToFilePath(icon);
 
176
        qrc_path = m_form->core()->iconCache()->iconToQrcPath(icon);
 
177
    }
 
178
 
 
179
    dialog.setPaths(qrc_path, file_path);
 
180
    if (dialog.exec()) {
 
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);
 
185
            item->setIcon(icon);
 
186
            ui.previewButton->setIcon(icon);
 
187
            ui.deleteButton->setEnabled(!icon.isNull());
 
188
        }
 
189
    }
 
190
}
 
191
 
 
192
int ListWidgetEditor::count() const
 
193
{
 
194
    return ui.listWidget->count();
 
195
}
 
196
 
 
197
QIcon ListWidgetEditor::icon(int row) const
 
198
{
 
199
    return ui.listWidget->item(row)->icon();
 
200
}
 
201
 
 
202
QString ListWidgetEditor::text(int row) const
 
203
{
 
204
    return ui.listWidget->item(row)->text();
 
205
}