summaryrefslogtreecommitdiffstats
path: root/kexi/widget/pixmapcollection.h
blob: caf11fd5e103e935a6542f7f2c1d2547f4ed08d7 (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
163
164
165
166
/* 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 <tqobject.h>
#include <tqmap.h>
#include <tqpair.h>
#include <tqintdict.h>
#include <tqtoolbutton.h>

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

class TQPixmap;
class KIconView;
class KIconButton;
class KLineEdit;
class TQDomNode;

typedef TQMap<TQString, TQPair<TQString, int> > PixmapMap;

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

	public:
		PixmapCollection(const TQString &collectionName, TQObject *tqparent = 0, const char *name = 0);
		~PixmapCollection() {;}

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

		bool   tqcontains(const TQString &name);
		TQPixmap  getPixmap(const TQString &name);

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

		TQString collectionName() {return m_name; }

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

	protected:
		TQString  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
  TQ_OBJECT

	public:
		PixmapCollectionEditor(PixmapCollection *collection, TQWidget *tqparent = 0);
		~PixmapCollectionEditor() {;}

	protected:
		TQPixmap getPixmap(const TQString &name);
		void createIconViewItem(const TQString &name);

	protected slots:
		void newItemByPath();
		void newItemByName();
		void removeItem();
		void renameItem();
		void renameCollectionItem(TQIconViewItem *item, const TQString &name);
		void displayMenu(TQIconViewItem *item, const TQPoint &p);

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

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

	public:
		PixmapCollectionChooser(PixmapCollection *collection, const TQString &selectedItem, TQWidget *tqparent = 0);
		~PixmapCollectionChooser() {;}

		TQPixmap  pixmap();
		TQString  pixmapName();

	protected:
		TQPixmap getPixmap(const TQString &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
  TQ_OBJECT

	public:
		LoadIconDialog(TQWidget *tqparent = 0);
		~LoadIconDialog() {;}

		int iconSize();
		TQString iconName();

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

	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 *tqparent, const TQString &text, const TQPixmap &icon)
		: KIconViewItem(tqparent, text, icon)  { m_name = text; }
		~PixmapIconViewItem() {;}

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

	private:
		TQString  m_name;
};

#endif