summaryrefslogtreecommitdiffstats
path: root/kicker/kicker/ui/itemview.h
blob: 27807c939c13087dcaf260e775ae131df79c87f8 (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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
/*****************************************************************

Copyright (c) 1996-2000 the kicker authors. See file AUTHORS.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

******************************************************************/

#ifndef __itemview_h__
#define __itemview_h__

#include <dcopobject.h>
#include <tqintdict.h>
#include <tqpixmap.h>
#include <tqframe.h>
#include <tqtoolbutton.h>
#include <tdelistview.h>
#include <tqdragobject.h>

#include "kmenubase.h"
#include "kmenuitembase.h"
#include "service_mnu.h"

class KickerClientMenu;
class KBookmarkMenu;
class TDEActionCollection;
class KBookmarkOwner;
class Panel;
class TQWidgetStack;
class KHistoryCombo;
class TQScrollView;
class PopupMenuTitle;
class TQWidget;
class TQVBoxLayout;
class TQTimer;
class KPixmap;

class KMenuItem : public TQListViewItem
{
public:
    KMenuItem(int nId, TQListView* parent) : TQListViewItem(parent), m_id(nId) { init(); }
    KMenuItem(int nId, TQListViewItem* parent) : TQListViewItem(parent), m_id(nId) { init(); }
    ~KMenuItem();

    void setIcon(const TQString& icon, int size);
    TQString icon() const { return m_icon; }
    void setTitle( const TQString& text );
    TQString title() const { return m_title; }
    void setToolTip( const TQString& text );
    TQString toolTip() const { return m_tooltip; }
    void setDescription(const TQString& text);
    TQString description() const { return m_description; }
    void setService(KService::Ptr& s) { m_s = s; }
    KService::Ptr service() { return m_s; }
    void setPath(const TQString& u) { m_path = u; }
    TQString path() const { return m_path; }
    void setMenuPath(const TQString& u) { m_menuPath = u; }
    TQString menuPath() const { return m_menuPath; }
    int id() const { return m_id; }
    void setHasChildren(bool flag);
    bool hasChildren() const { return m_has_children; }
    void makeGradient(KPixmap &off, const TQColor& c);

protected:
    virtual void paintCell(TQPainter* p, const TQColorGroup & cg, int column, int width, int align);
    virtual void paintCellInter(TQPainter* p, const TQColorGroup & cg, int column, int width, int align);
    virtual void setup();

private:
    void init();

    int m_id;
    KService::Ptr m_s;
    TQString m_title;
    TQString m_description;
    TQString m_path;
    TQString m_icon;
    TQString m_tooltip;
    TQString m_menuPath;
    float title_font_size;
    float description_font_size;
    bool m_has_children;
    int m_old_width;
    TQPixmap right_triangle;
};

class KMenuItemSeparator : public KMenuItem
{
public:
    KMenuItemSeparator(int nId, TQListView* parent);
    virtual void setup();

    virtual void paintCell(TQPainter* p, const TQColorGroup & cg, int column, int width, int align);
    void setLink(const TQString &text, const TQString &link = TQString::null );

    TQString linkUrl() const { return m_link_url; }

    /// returns true if the cursor has to change
    bool hitsLink(const TQPoint &pos);

protected:
    void preparePixmap(int width);
    TQPixmap pixmap;
    int left_margin;

private:
    TQListView* lv;
    int cached_width;
    TQString m_link_text, m_link_url;
    TQRect m_link_rect;

};

class KMenuItemHeader : public KMenuItemSeparator
{
public:
    KMenuItemHeader( int nId, const TQString &relpath, TQListView* parent);
    virtual void setup();

    virtual void paintCell(TQPainter* p, const TQColorGroup & cg, int column, int width, int align);

private:
    TQListView* lv;
    TQStringList paths;
    TQStringList texts;
    TQStringList icons;
    TQPixmap left_triangle;
};

class KMenuSpacer : public KMenuItem
{
public:
    KMenuSpacer(int nId, TQListView* parent);
    virtual void paintCell(TQPainter* p, const TQColorGroup & cg, int column, int width, int align);
    virtual void setup();

    void setHeight(int);
};

class ItemView : public TDEListView
{
    friend class KMenuItem;

    Q_OBJECT
public:
    ItemView(TQWidget* parent, const char* name = 0);

    KMenuItem* insertItem( const TQString& icon, const TQString& text, const TQString& description, int nId, int nIndex, KMenuItem* parentItem = 0 );
    KMenuItem* insertItem( const TQString& icon, const TQString& text, const TQString& description, const TQString& path, int nId, int nIndex, KMenuItem* parentItem = 0 );
    int insertItem( PopupMenuTitle*, int, int);
    int setItemEnabled(int id, bool enabled);
    KMenuItemSeparator *insertSeparator(int id, const TQString& text, int nIndex);
    KMenuItemHeader *insertHeader(int id, const TQString &relpath);
    KMenuItem* insertMenuItem(KService::Ptr & s, int nId, int nIndex = -1, KMenuItem* parentItem = 0,
                        const TQString &aliasname = TQString::null, const TQString &label = TQString::null,
                        const TQString &categoryIcon = TQString::null);
    KMenuItem* insertRecentlyItem(const TQString& s, int nId, int nIndex = -1);
    KMenuItem* insertDocumentItem(const TQString& s, int nId, int nIndex = -1 , const TQStringList* suppressGenericNames = 0,
                        const TQString& aliasname = TQString::null);
    KMenuItem* insertSubItem(const TQString& icon, const TQString& caption, const TQString& description, const TQString& path, KMenuItem* parentItem);
    KMenuItem* findItem(int nId);

    void setIconSize(int size) { m_iconSize = size; }
    void setMouseMoveSelects(bool select) { m_mouseMoveSelects = select; }
    void clear();
    int goodHeight();
    TQString path;
    void setBackPath( const TQString &str ) { m_back_url = str; }
    TQString backPath() const { return m_back_url; }

public slots:
    void slotItemClicked(TQListViewItem*);
    void slotMoveContent();

signals:
    void startService(KService::Ptr kservice);
    void startURL(const TQString& u);

protected:
    void contentsMouseMoveEvent(TQMouseEvent *e);
    void contentsMousePressEvent ( TQMouseEvent * e );
    void contentsWheelEvent(TQWheelEvent *e);
    void leaveEvent(TQEvent *e);
    virtual void resizeEvent ( TQResizeEvent * e );
    virtual void viewportPaintEvent ( TQPaintEvent * pe );
    virtual TQDragObject* dragObject ();
    virtual bool acceptDrag (TQDropEvent* event) const;
    virtual bool focusNextPrevChild(bool next);

private slots:
    void slotItemClicked(int button, TQListViewItem * item, const TQPoint & pos, int c );

private:
    KMenuItem* itemAtIndex(int nIndex);
    void moveItemToIndex(KMenuItem*, int);

    TQWidget* m_itemBox;
    TQVBoxLayout* m_itemLayout;
    KMenuItem *m_lastOne;
    KMenuSpacer *m_spacer;

    TQString m_back_url;

    bool m_mouseMoveSelects;
    int m_iconSize;
    int m_old_contentY;
};

class FavoritesItemView : public ItemView
{
public:
    FavoritesItemView(TQWidget* parent, const char* name = 0);

protected:
    virtual bool acceptDrag (TQDropEvent* event) const;
};

class KMenuItemInfo
{
public:
    int m_id;
    KService::Ptr m_s;
    TQString m_title;
    TQString m_description;
    TQString m_path;
    TQString m_icon;
};

class KMenuItemDrag : public TQDragObject
{
    public:
        KMenuItemDrag(KMenuItem& item, TQWidget *dragSource);
        ~KMenuItemDrag();

        virtual const char * format(int i = 0) const;
        virtual TQByteArray encodedData(const char *) const;

        static bool canDecode(const TQMimeSource * e);
        static bool decode(const TQMimeSource* e, KMenuItemInfo& item);

    private:
        TQByteArray a;
};

#endif