summaryrefslogtreecommitdiffstats
path: root/digikam/libs/thumbbar/thumbbar.h
blob: 48ac574d5b1d556dc3a8a8e446c204a14c0d64c2 (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
/* ============================================================
 *
 * This file is a part of digiKam project
 * http://www.digikam.org
 *
 * Date        : 2004-11-22
 * Description : a bar widget to display image thumbnails
 *
 * Copyright (C) 2004-2005 by Renchi Raju <renchi@pooh.tam.uiuc.edu>
 * Copyright (C) 2005-2008 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.
 *
 * ============================================================ */

#ifndef THUMBBAR_H
#define THUMBBAR_H

// TQt includes.

#include <tqstring.h>
#include <tqscrollview.h>
#include <tqtooltip.h>

// KDE includes.

#include <kurl.h>

// Local includes.

#include "digikam_export.h"

namespace Digikam
{

class ThumbBarItem;
class ThumbBarToolTip;
class ThumbBarViewPriv;
class ThumbBarItemPriv;

class DIGIKAM_EXPORT ThumbBarToolTipSettings 
{
public:

    ThumbBarToolTipSettings()
    {
        showToolTips   = true;
        showFileName   = true;
        showFileDate   = false;
        showFileSize   = false;
        showImageType  = false;
        showImageDim   = true;
        showPhotoMake  = true;
        showPhotoDate  = true;
        showPhotoFocal = true;
        showPhotoExpo  = true;
        showPhotoMode  = true;
        showPhotoFlash = false;
        showPhotoWB    = false;
    };

    bool showToolTips;
    bool showFileName;
    bool showFileDate;
    bool showFileSize;
    bool showImageType;
    bool showImageDim;
    bool showPhotoMake;
    bool showPhotoDate;
    bool showPhotoFocal;
    bool showPhotoExpo;
    bool showPhotoMode;
    bool showPhotoFlash;
    bool showPhotoWB;
};

// -------------------------------------------------------------------------

class DIGIKAM_EXPORT ThumbBarView : public TQScrollView
{
    TQ_OBJECT
  

public:

    enum Orientation
    {
       Horizontal=0,
       Vertical
    };

public:

    ThumbBarView(TQWidget* parent, int orientation=Vertical, bool exifRotate=true,
                 ThumbBarToolTipSettings settings=ThumbBarToolTipSettings());
    virtual ~ThumbBarView();

    int countItems();
    KURL::List itemsURLs();

    void clear(bool updateView=true);
    void triggerUpdate();

    void removeItem(ThumbBarItem* item);

    void setSelected(ThumbBarItem* item);
    void ensureItemVisible(ThumbBarItem* item);

    void setExifRotate(bool exifRotate);
    bool getExifRotate();

    void setToolTipSettings(const ThumbBarToolTipSettings &settings);
    ThumbBarToolTipSettings& getToolTipSettings();

    ThumbBarItem* currentItem() const;
    ThumbBarItem* firstItem() const;
    ThumbBarItem* lastItem()  const;
    ThumbBarItem* findItem(const TQPoint& pos) const;
    ThumbBarItem* findItemByURL(const KURL& url) const;

    void refreshThumbs(const KURL::List& urls);
    void invalidateThumb(ThumbBarItem* item);

signals:

    void signalItemSelected(ThumbBarItem*);
    void signalURLSelected(const KURL&);
    void signalItemAdded();

protected:

    int  getOrientation();
    int  getTileSize();
    int  getMargin();

    void resizeEvent(TQResizeEvent*);
    void contentsMousePressEvent(TQMouseEvent*);
    void contentsMouseMoveEvent(TQMouseEvent*);
    void contentsMouseReleaseEvent(TQMouseEvent*);
    void contentsWheelEvent(TQWheelEvent*);

    void insertItem(ThumbBarItem* item);
    void rearrangeItems();
    void repaintItem(ThumbBarItem* item);

    virtual void viewportPaintEvent(TQPaintEvent*);
    virtual void startDrag();

protected slots:

    void slotUpdate();

private slots:

    void slotGotThumbnail(const KURL&, const TQPixmap&);
    void slotFailedThumbnail(const KURL&);

private:

    ThumbBarViewPriv* d;

    friend class ThumbBarItem;
};

// -------------------------------------------------------------------------

class DIGIKAM_EXPORT ThumbBarItem
{
public:

    ThumbBarItem(ThumbBarView *view, const KURL& url);
    virtual ~ThumbBarItem();

    KURL          url() const;

    ThumbBarItem* next() const;
    ThumbBarItem* prev() const;
    int           position() const;
    TQRect         rect() const;
    TQPixmap*      pixmap() const;

    void          repaint();

private:

    ThumbBarItemPriv* d;

    friend class ThumbBarView;
};

// -------------------------------------------------------------------------

class DIGIKAM_EXPORT ThumbBarToolTip : public TQToolTip
{

public:

    ThumbBarToolTip(ThumbBarView *parent);
    virtual ~ThumbBarToolTip(){};

protected:

    const uint    m_maxStringLen;

    TQString       m_headBeg;
    TQString       m_headEnd;
    TQString       m_cellBeg;
    TQString       m_cellMid;
    TQString       m_cellEnd;
    TQString       m_cellSpecBeg;
    TQString       m_cellSpecMid;
    TQString       m_cellSpecEnd;

    ThumbBarView *m_view;

protected:

    TQString breakString(const TQString& input);

    virtual TQString tipContentExtraData(ThumbBarItem*){ return TQString(); };

private:

    void maybeTip(const TQPoint& pos);
    TQString tipContent(ThumbBarItem* item);
};

}  // NameSpace Digikam

#endif /* THUMBBAR_H */