]> cloud.milkyroute.net Git - dolphin.git/blob - src/infosidebarpage.h
fixed some activation issues in combination with split views
[dolphin.git] / src / infosidebarpage.h
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at> *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
19
20 #ifndef INFOSIDEBARPAGE_H
21 #define INFOSIDEBARPAGE_H
22
23 #include <sidebarpage.h>
24
25 #include <QtGui/QPushButton>
26 #include <QtGui/QPixmap>
27 #include <QtCore/QEvent>
28 #include <QtGui/QLabel>
29 #include <QtCore/QList>
30
31 #include <kurl.h>
32 #include <kmimetype.h>
33 #include <kdesktopfileactions.h>
34 #include <kvbox.h>
35
36 class QPixmap;
37 class QString;
38 class KFileItem;
39 class QLabel;
40 class PixmapViewer;
41 class MetaDataWidget;
42
43 /**
44 * @brief Sidebar for showing meta information of one ore more selected items.
45 */
46 class InfoSidebarPage : public SidebarPage
47 {
48 Q_OBJECT
49
50 public:
51 explicit InfoSidebarPage(QWidget* parent = 0);
52 virtual ~InfoSidebarPage();
53
54 public slots:
55 /** @see SidebarPage::setUrl() */
56 virtual void setUrl(const KUrl& url);
57
58 /** @see SidebarPage::setSelection() */
59 virtual void setSelection(const KFileItemList& selection);
60
61 /**
62 * Does a delayed request of information for the item of the given URL.
63 * If within this delay InfoSidebarPage::setUrl() or InfoSidebarPage::setSelection()
64 * are invoked, then the request will be skipped. Requesting a delayed item information
65 * makes sense when hovering items.
66 */
67 void requestDelayedItemInfo(const KUrl& url);
68
69 protected:
70 /** @see QWidget::showEvent() */
71 virtual void showEvent(QShowEvent* event);
72
73 /** @see QWidget::resizeEvent() */
74 virtual void resizeEvent(QResizeEvent* event);
75
76 private slots:
77 /**
78 * Shows the information for the item of the URL which has been provided by
79 * InfoSidebarPage::requestItemInfo() and provides default actions.
80 */
81 void showItemInfo();
82
83 /**
84 * Triggered if the request for item information has timed out.
85 * @see InfoSidebarPage::requestDelayedItemInfo()
86 */
87 void slotTimeout();
88
89 /**
90 * Is invoked if no preview is available for the item. In this
91 * case the icon will be shown.
92 */
93 void showIcon(const KFileItem& item);
94
95 /**
96 * Is invoked if a preview is available for the item. The preview
97 * \a pixmap is shown inside the info page.
98 */
99 void showPreview(const KFileItem& item, const QPixmap& pixmap);
100
101 private:
102 enum { TimerDelay = 300 };
103
104 /**
105 * Checks whether the an URL is repesented by a bookmark. If yes,
106 * then the bookmark icon and name are shown instead of a preview.
107 * @return True, if the URL represents exactly a bookmark.
108 * @param url The url to check.
109 */
110 bool applyBookmark(const KUrl& url);
111
112 /** Assures that any pending item information request is cancelled. */
113 void cancelRequest();
114
115 /**
116 * Shows the meta information for the current shown item inside
117 * a label.
118 */
119 void showMetaInfo();
120
121 /**
122 * Adds the texts \a labelText and \a infoText as one formated line
123 * to text.
124 */
125 void addInfoLine(QString& text,
126 const QString& labelText,
127 const QString& infoText);
128
129 /**
130 * Converts the meta key \a key to a readable format into \a text.
131 * Returns true, if the string \a key represents a meta information
132 * that should be shown. If false is returned, \a text is not modified.
133 */
134 bool convertMetaInfo(const QString& key, QString& text) const;
135
136 private:
137 bool m_pendingPreview;
138 QTimer* m_timer;
139 KUrl m_shownUrl;
140 KUrl m_urlCandidate;
141
142 PixmapViewer* m_preview;
143 QLabel* m_nameLabel;
144
145 QLabel* m_infoLabel;
146
147 MetaDataWidget* m_metadataWidget;
148 };
149
150 #endif // INFOSIDEBARPAGE_H