summaryrefslogtreecommitdiffstats
path: root/kexi/widget/pixmapcollection.h
blob: a46a20438c116bdac7152c49ed6248188f680174 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/* This file is part of the KDE project
   Copyright (C) 2004 Cedric Pasteur <cedric.pasteur@free.fr>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
*/

#ifndef KFORMDESIGNERPIXMAPCOLLECTION_H
#define KFORMDESIGNERPIXMAPCOLLECTION_H

#include <qobject.h>
#include <qmap.h>
#include <qpair.h>
#include <qintdict.h>
#include <qtoolbutton.h>

#include <kicontheme.h>
#include <kdialogbase.h>
#include <kiconview.h>
#include <kurl.h>

class QPixmap;
class KIconView;
class KIconButton;
class KLineEdit;
class QDomNode;

typedef QMap<QString, QPair<QString, int> > PixmapMap;

//! A class that store pixmaps (by path or by name for KDE icons)
class KEXIEXTWIDGETS_EXPORT PixmapCollection : public QObject
{
	Q_OBJECT

	public:
		PixmapCollection(const QString &collectionName, QObject *parent = 0, const char *name = 0);
		~PixmapCollection() {;}

		QString addPixmapPath(const KURL &url);
		QString addPixmapName(const QString &name, int size = KIcon::SizeMedium);
		void removePixmap(const QString &name);

		bool   contains(const QString &name);
		QPixmap  getPixmap(const QString &name);

		void save(QDomNode parentNode);
		void load(QDomNode node);

		QString collectionName() {return m_name; }

	signals:
		void itemRenamed(const QString &oldName, const QString &newName);
		void itemRemoved(const QString &name);

	protected:
		QString  m_name;
		PixmapMap  m_pixmaps;

	friend class PixmapCollectionEditor;
	friend class PixmapCollectionChooser;
};

//! A dialog to edit the contents of a PixmapCollection
class KEXIEXTWIDGETS_EXPORT PixmapCollectionEditor : public KDialogBase
{
	Q_OBJECT

	public:
		PixmapCollectionEditor(PixmapCollection *collection, QWidget *parent = 0);
		~PixmapCollectionEditor() {;}

	protected:
		QPixmap getPixmap(const QString &name);
		void createIconViewItem(const QString &name);

	protected slots:
		void newItemByPath();
		void newItemByName();
		void removeItem();
		void renameItem();
		void renameCollectionItem(QIconViewItem *item, const QString &name);
		void displayMenu(QIconViewItem *item, const QPoint &p);

	private:
		enum { BNewItemPath = 101, BNewItemName, BDelItem};
		KIconView  *m_iconView;
		QIntDict<QToolButton>  m_buttons;
		PixmapCollection  *m_collection;
};

//! A dialog to choose an icon in a PixmapCollection
class KEXIEXTWIDGETS_EXPORT PixmapCollectionChooser : public KDialogBase
{
	Q_OBJECT

	public:
		PixmapCollectionChooser(PixmapCollection *collection, const QString &selectedItem, QWidget *parent = 0);
		~PixmapCollectionChooser() {;}

		QPixmap  pixmap();
		QString  pixmapName();

	protected:
		QPixmap getPixmap(const QString &name);
	protected slots:
		virtual void slotUser1();

	private:
		PixmapCollection  *m_collection;
		KIconView  *m_iconView;
};

//! A simple dialog to choose a KDE icon
class KEXIEXTWIDGETS_EXPORT LoadIconDialog : public KDialogBase
{
	Q_OBJECT

	public:
		LoadIconDialog(QWidget *parent = 0);
		~LoadIconDialog() {;}

		int iconSize();
		QString iconName();

	protected slots:
		void changeIconSize(int);
		void updateIconName(QString);
		void setIcon(const QString &);

	private:
		KLineEdit *m_nameInput;
		KIconButton *m_button;
};

//! A Special KIconViewItem that holds the name of its associated pixmap (to allow renaming)
class KEXIEXTWIDGETS_EXPORT PixmapIconViewItem : public KIconViewItem
{
	public:
		PixmapIconViewItem(KIconView *parent, const QString &text, const QPixmap &icon)
		: KIconViewItem(parent, text, icon)  { m_name = text; }
		~PixmapIconViewItem() {;}

		void setName(const QString &name) { m_name = name; }
		QString name() { return m_name;}

	private:
		QString  m_name;
};

#endif