summaryrefslogtreecommitdiffstats
path: root/digikam/digikam/searchwidgets.h
blob: 75ca51ceac9313430ce2bfd6ad54eaac5ac8a39e (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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
/* ============================================================
 *
 * This file is a part of digiKam project
 * http://www.digikam.org
 *
 * Date        : 2005-01-01
 * Description : 
 * 
 * Copyright (C) 2005 by Renchi Raju <renchi@pooh.tam.uiuc.edu>
 * Copyright (C) 2005 by Tom Albers <tomalbers@kde.nl>
 * Copyright (C) 2006-2007 by Gilles Caulier <caulier dot gilles at gmail dot com>
 *
 * This program is free software; you can redistribute it
 * and/or modify it under the terms of the GNU General
 * Public License as published by the Free Software Foundation;
 * either version 2, or (at your option)
 * any later version.
 * 
 * This program 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 General Public License for more details.
 * 
 * ============================================================ */

/** @file searchwidgets.h */

#ifndef SEARCHWIDGETS_H
#define SEARCHWIDGETS_H

class TQHBox;
class TQVBox;
class TQCheckBox;
class TQComboBox;
class TQLineEdit;
class TQLabel;
class TQVGroupBox;
class TQLabel;

class KURL;
class KDateEdit;

namespace Digikam
{

class RatingWidget;
class SqueezedComboBox;

/** @class SearchRuleLabel
 *
 * This class inherits everything from TQLabel, and adds one
 * signal to it, when double clicked on it.
 */
class SearchRuleLabel: public TQLabel
{
    TQ_OBJECT

public:

    /** Constructor. See for more info the TQLabel clas.
     * @param text Text of the label
     * @param parent The parent widget
     * @param name The name
     * @param f WFlags
     */
    SearchRuleLabel(const TQString & text,
                    TQWidget * parent,
                    const char * name=0,
                    WFlags f=0 );

signals:

    /**
     * Signal which gets emitted when a double clicked
     * event occurs
     * @param e the mouse event received
     */
    void signalDoubleClick( TQMouseEvent * e );

private:

    void mouseDoubleClickEvent( TQMouseEvent * e );
};

/** @class SearchAdvancedBase
 *
 * This class is a common class for SearchAdvancedRule and
 * SearchAdvancedGroup. It contains the basic functionality
 * for the advanced search dialog.
 * @author Renchi Raju
 * @author Tom Albers
 * 
 */
class SearchAdvancedBase : public TQObject
{
    TQ_OBJECT

public:

    /** @enum Type
     * Possible types. A Base item can either be a Rule on its own
     * or hold a group of rules.
     */
    enum Type
    {
        RULE = 0,
        GROUP
    };

    /** @enum Option
     * Possible Options. A Rule or a group of rules can have a relation
     * to the previous rule or group of rules. None can be used for the
     * first rule or group.
     */
    enum Option
    {
        NONE = 0,
        AND,
        OR
    };

    /**
     * Constructor
     * @param type Determines which type of base item to be created.
     */
    SearchAdvancedBase(Type type): m_type(type) {}
    
    /**
     * Destructor
     */
    virtual ~SearchAdvancedBase() {}

    /**
     * Returns the type of the base item
     * @return The type which is a enum, see above
     */
    Type type() const { return m_type; }

    /**
     * Returns a pointer to the widget holding the base item
     * @return Pointer to the widget
     */
    virtual TQWidget* widget() const = 0;

    /**
     * Determines if the base item is checked or not
     * @return true if the base item is checked and false if not
     */
    virtual bool     isChecked() const = 0;

    /**
     * Returns the option which is accociated with the base item
     * @return The Option which is a enum, see above
     */
    Option  option() const { return m_option; }

    /**
     * Sets the option of the base item
     * @param option The enum of the option to be set
     */
    virtual void addOption(Option option) = 0;

    /**
     * Removes the option of the base item
     */
    virtual void removeOption() = 0;

signals:
    /**
     * This signal is emitted when a rule or group is checked or unchecked
     * This is used to determine the state of the buttons of the dialog
     */
    void signalBaseItemToggled();

    /**
     * This signal is emitted when there is a change in the rule.
     * This is used in the dialog to recalculate the url to pass to the
     * preview widget
     */
    void signalPropertyChanged();

protected:

    enum Option m_option;
    enum Type m_type;
};

class SearchAdvancedGroup;

/** @class SearchAdvancedRule
 * This inherits SearchAdvancedBase and is one rule in the search dialog
 * it contains all widgets to create a rule
 */
class SearchAdvancedRule :  public SearchAdvancedBase
{
    TQ_OBJECT

public:
    /**
     * Constructor
     * @param parent The parent
     * @param option Holds the Option of the rule, see the enum.
     *
     */
    SearchAdvancedRule(TQWidget* parent, Option option);

    /**
     * destructor
     */
    ~SearchAdvancedRule();

    /**
     * Returns a pointer to the widget holding the rule
     * @return Pointer to the widget
     */
    TQWidget* widget() const;

    /**
     * Determines if the rule is checked or not
     * @return True if the rule is checked, false if not
     */
    bool     isChecked() const;

    /**
     * Sets the values of the rule.
     * @param url The url which sets defaults for the rule.
     */
    void    setValues(const KURL& url);

    /**
     * Sets the option of the rule, so this holds the
     * relation ship to the previous rule or group
     * @param option the enum of the option to be set
     */
    void    addOption(Option option);

    /**
     * Removes the option of the rule
     */
    void    removeOption();

    /**
     * This adds the checkbox at the end of the rule. This is needed
     * for example when a group of rules get ungrouped.
     */
    void    addCheck();

    /**
     * This removes the checkbox at the end of the rule, this is
     * used if the rule is a part of a group. In a group the group
     * has the checkbox, not the individual rules.
     */
    void    removeCheck();

    /**
     * Gives back the value of the key part of the rule, which can
     * be used to build the correct url for the tdeio
     * @return The value of the key part of the rule
     */
    TQString urlKey() const;

    /**
     * Gives back the value of the operator part of the rule, which can
     * be used to build the correct url for the tdeio
     * @return The value of the operator part of the rule
     */
    TQString urlOperator() const;

    /**
     * Gives back the value of the value part of the rule, which can
     * be used to build the correct url for the tdeio
     * @return The value of the value part of the rule
     */
    TQString urlValue() const;

    enum valueWidgetTypes
    {
        NOWIDGET = 0,
        LINEEDIT,
        DATE,
        ALBUMS,
        TAGS,
        RATING
    };

private:

    void setValueWidget(valueWidgetTypes oldType, valueWidgetTypes newType);

private slots:

    void slotKeyChanged(int);
    void slotLabelDoubleClick();

private:

    TQLabel*                 m_label;

    TQVBox*                  m_box;
    TQWidget*                m_hbox;
    TQHBoxLayout*            m_hboxLayout;

    TQHBox*                  m_valueBox;

    TQCheckBox*              m_check;

    TQComboBox*              m_key;
    TQComboBox*              m_operator;

    TQLineEdit*              m_lineEdit;
    KDateEdit*              m_dateEdit;
    SqueezedComboBox*       m_valueCombo;
    RatingWidget*           m_ratingWidget;

    TQMap<int, int>          m_itemsIndexIDMap;

    TQHBox*                  m_optionsBox;

    enum valueWidgetTypes   m_widgetType;
};

/** @class SearchAdvancedGroup
 * This inherits SearchAdvancedBase and is a group of rules
 * in the search dialog
 */
class SearchAdvancedGroup : public SearchAdvancedBase
{

public:
    /**
     * Constructor
     * @param parent the parent
     */
    SearchAdvancedGroup(TQWidget* parent);

    /**
     * Destructor
     */
    ~SearchAdvancedGroup();

     /**
     * Returns a pointer to the widget holding the group
     * @return pointer to the widget
     */
    TQWidget* widget() const;

    /**
     * determines if the rule is checked or not
     * @return bool, which indicated if the base item is checked
     */
    bool isChecked() const;

    /**
     * sets the option of the group
     * @param option the enum of the option to be set
     */
    void addOption(Option option);

    /**
     * removes the option
     */
    void removeOption();

    /**
     * adds a rule to group
     * @param rule the pointer to the rule to be added to the group
     */
    void addRule(SearchAdvancedRule* rule);

    /**
     * removes all rules from the group
     */
    void removeRules();

    /**
     * gives back a list of pointers to the rules inside the group
     * @return a list of pointers to the childeren in the group
     */
    TQValueList<SearchAdvancedRule*> childRules() const;

private:

    TQHBox*                          m_box;
    TQVGroupBox*                     m_groupbox;
    TQCheckBox*                      m_check;
    TQValueList<SearchAdvancedRule*> m_childRules;
};

}  // namespace Digikam

#endif /* SEARCHWIDGETS_H */