Changeset View
Changeset View
Standalone View
Standalone View
src/panels/information/informationpanel.cpp
Show All 20 Lines | |||||
21 | 21 | | |||
22 | #include "informationpanelcontent.h" | 22 | #include "informationpanelcontent.h" | ||
23 | 23 | | |||
24 | #include <KIO/Job> | 24 | #include <KIO/Job> | ||
25 | #include <KIO/JobUiDelegate> | 25 | #include <KIO/JobUiDelegate> | ||
26 | #include <KJobWidgets> | 26 | #include <KJobWidgets> | ||
27 | #include <KDirNotify> | 27 | #include <KDirNotify> | ||
28 | 28 | | |||
29 | #include <Baloo/FileMetaDataWidget> | ||||
30 | | ||||
29 | #include <QApplication> | 31 | #include <QApplication> | ||
30 | #include <QShowEvent> | 32 | #include <QShowEvent> | ||
31 | #include <QVBoxLayout> | 33 | #include <QVBoxLayout> | ||
32 | #include <QTimer> | 34 | #include <QTimer> | ||
35 | #include <QMenu> | ||||
36 | #include <KLocalizedString> | ||||
37 | | ||||
38 | #include "dolphin_informationpanelsettings.h" | ||||
39 | #include "filemetadataconfigurationdialog.h" | ||||
33 | 40 | | |||
34 | InformationPanel::InformationPanel(QWidget* parent) : | 41 | InformationPanel::InformationPanel(QWidget* parent) : | ||
35 | Panel(parent), | 42 | Panel(parent), | ||
43 | m_parent(parent), | ||||
36 | m_initialized(false), | 44 | m_initialized(false), | ||
37 | m_infoTimer(nullptr), | 45 | m_infoTimer(nullptr), | ||
38 | m_urlChangedTimer(nullptr), | 46 | m_urlChangedTimer(nullptr), | ||
39 | m_resetUrlTimer(nullptr), | 47 | m_resetUrlTimer(nullptr), | ||
40 | m_shownUrl(), | 48 | m_shownUrl(), | ||
41 | m_urlCandidate(), | 49 | m_urlCandidate(), | ||
42 | m_invalidUrlCandidate(), | 50 | m_invalidUrlCandidate(), | ||
43 | m_fileItem(), | 51 | m_fileItem(), | ||
▲ Show 20 Lines • Show All 108 Lines • ▼ Show 20 Line(s) | 159 | if (isVisible()) { | |||
152 | m_urlCandidate = m_shownUrl; | 160 | m_urlCandidate = m_shownUrl; | ||
153 | m_infoTimer->start(); | 161 | m_infoTimer->start(); | ||
154 | } | 162 | } | ||
155 | Panel::resizeEvent(event); | 163 | Panel::resizeEvent(event); | ||
156 | } | 164 | } | ||
157 | 165 | | |||
158 | void InformationPanel::contextMenuEvent(QContextMenuEvent* event) | 166 | void InformationPanel::contextMenuEvent(QContextMenuEvent* event) | ||
159 | { | 167 | { | ||
160 | // TODO: Move code from InformationPanelContent::configureSettings() here | 168 | QMenu popup(m_parent); | ||
161 | m_content->configureSettings(customContextMenuActions(), event->globalPos()); | 169 | | ||
170 | QAction* previewAction = popup.addAction(i18nc("@action:inmenu", "Preview")); | ||||
171 | previewAction->setIcon(QIcon::fromTheme(QStringLiteral("view-preview"))); | ||||
172 | previewAction->setCheckable(true); | ||||
173 | previewAction->setChecked(InformationPanelSettings::previewsShown()); | ||||
174 | | ||||
175 | QAction* configureAction = popup.addAction(i18nc("@action:inmenu", "Configure...")); | ||||
176 | configureAction->setIcon(QIcon::fromTheme(QStringLiteral("configure"))); | ||||
177 | | ||||
178 | QAction* dateformatAction = popup.addAction(i18nc("@action:inmenu", "Condensed Date")); | ||||
179 | dateformatAction->setIcon(QIcon::fromTheme(QStringLiteral("change-date-symbolic"))); | ||||
180 | dateformatAction->setCheckable(true); | ||||
181 | dateformatAction->setChecked(InformationPanelSettings::dateFormat() == static_cast<int>(Baloo::DateFormats::ShortFormat)); | ||||
182 | | ||||
183 | popup.addSeparator(); | ||||
184 | foreach (QAction* action, customContextMenuActions()) { | ||||
185 | popup.addAction(action); | ||||
186 | } | ||||
187 | | ||||
188 | // Open the popup and adjust the settings for the | ||||
189 | // selected action. | ||||
190 | QAction* action = popup.exec(event->globalPos()); | ||||
191 | if (!action) { | ||||
192 | return; | ||||
193 | } | ||||
194 | | ||||
195 | const bool isChecked = action->isChecked(); | ||||
196 | if (action == previewAction) { | ||||
197 | InformationPanelSettings::setPreviewsShown(isChecked); | ||||
198 | m_content->refreshMetaData(); | ||||
199 | } else if (action == configureAction) { | ||||
200 | FileMetaDataConfigurationDialog* dialog = new FileMetaDataConfigurationDialog(this); | ||||
201 | dialog->setDescription(i18nc("@label::textbox", | ||||
202 | "Select which data should be shown in the information panel:")); | ||||
203 | dialog->setItems(m_content->items()); | ||||
204 | dialog->setAttribute(Qt::WA_DeleteOnClose); | ||||
205 | dialog->show(); | ||||
206 | connect(dialog, &FileMetaDataConfigurationDialog::destroyed, m_content, &InformationPanelContent::refreshMetaData); | ||||
207 | } | ||||
208 | if (action == dateformatAction) { | ||||
209 | int dateFormat = static_cast<int>(isChecked ? Baloo::DateFormats::ShortFormat : Baloo::DateFormats::LongFormat); | ||||
210 | | ||||
211 | InformationPanelSettings::setDateFormat(dateFormat); | ||||
212 | m_content->refreshMetaData(); | ||||
213 | } | ||||
214 | | ||||
anthonyfieroni: Do not parent object on the stack, if its parent gets destroyed before, destructor will be… | |||||
meven: This means I should use Qmenu popup(parent) ? | |||||
162 | Panel::contextMenuEvent(event); | 215 | Panel::contextMenuEvent(event); | ||
163 | } | 216 | } | ||
164 | 217 | | |||
165 | void InformationPanel::showItemInfo() | 218 | void InformationPanel::showItemInfo() | ||
166 | { | 219 | { | ||
167 | if (!isVisible()) { | 220 | if (!isVisible()) { | ||
168 | return; | 221 | return; | ||
169 | } | 222 | } | ||
▲ Show 20 Lines • Show All 196 Lines • Show Last 20 Lines |
Do not parent object on the stack, if its parent gets destroyed before, destructor will be called twice.