From 307285e9635a4bf584d6e5d7478876b90ef870f0 Mon Sep 17 00:00:00 2001 From: Peter Penz Date: Wed, 14 Jan 2009 19:26:23 +0000 Subject: Group classes into folders, Dolphin is too big in the meantime for having a flat directory hierarchy. dolphin/src/CMakeLists.txt will be cleaned up later. svn path=/trunk/KDE/kdebase/apps/; revision=911065 --- src/CMakeLists.txt | 118 ++- src/additionalinfodialog.cpp | 102 -- src/additionalinfodialog.h | 53 -- src/applyviewpropsjob.cpp | 81 -- src/applyviewpropsjob.h | 83 -- src/columnviewsettingspage.cpp | 155 --- src/columnviewsettingspage.h | 61 -- src/commenteditwidget.cpp | 241 ----- src/commenteditwidget.h | 62 -- src/commentwidget.cpp | 114 --- src/commentwidget.h | 48 - src/detailsviewsettingspage.cpp | 147 --- src/detailsviewsettingspage.h | 60 -- src/dolphin_columnmodesettings.kcfg | 41 - src/dolphin_columnmodesettings.kcfgc | 4 - src/dolphin_detailsmodesettings.kcfg | 41 - src/dolphin_detailsmodesettings.kcfgc | 4 - src/dolphin_directoryviewpropertysettings.kcfg | 65 -- src/dolphin_directoryviewpropertysettings.kcfgc | 6 - src/dolphin_folderspanelsettings.kcfg | 11 - src/dolphin_folderspanelsettings.kcfgc | 4 - src/dolphin_generalsettings.kcfg | 71 -- src/dolphin_generalsettings.kcfgc | 4 - src/dolphin_iconsmodesettings.kcfg | 67 -- src/dolphin_iconsmodesettings.kcfgc | 4 - src/dolphincolumnview.cpp | 2 +- src/dolphincolumnwidget.cpp | 4 +- src/dolphincontextmenu.cpp | 2 +- src/dolphindetailsview.cpp | 2 +- src/dolphinfileplacesview.cpp | 56 -- src/dolphinfileplacesview.h | 51 - src/dolphinfontrequester.cpp | 111 --- src/dolphinfontrequester.h | 79 -- src/dolphiniconsview.cpp | 2 +- src/dolphinmainwindow.cpp | 14 +- src/dolphinmainwindow.h | 2 +- src/dolphinsettings.cpp | 78 -- src/dolphinsettings.h | 92 -- src/dolphinsettingsdialog.cpp | 114 --- src/dolphinsettingsdialog.h | 60 -- src/dolphinstatusbar.cpp | 2 +- src/dolphintooltip.cpp | 50 - src/dolphintooltip.h | 47 - src/dolphinview.cpp | 4 +- src/dolphinviewactionhandler.cpp | 2 +- src/dolphinviewcontainer.cpp | 2 +- src/folderexpander.cpp | 2 +- src/generalsettingspage.cpp | 170 ---- src/generalsettingspage.h | 64 -- src/generalviewsettingspage.cpp | 201 ---- src/generalviewsettingspage.h | 73 -- src/iconsizegroupbox.cpp | 116 --- src/iconsizegroupbox.h | 66 -- src/iconsviewsettingspage.cpp | 243 ----- src/iconsviewsettingspage.h | 88 -- src/infosidebarpage.cpp | 587 ------------ src/infosidebarpage.h | 194 ---- src/kcmdolphin.cpp | 8 +- src/kformattedballoontipdelegate.cpp | 129 --- src/kformattedballoontipdelegate.h | 45 - src/ktooltip.cpp | 558 ----------- src/ktooltip.h | 198 ---- src/ktooltip_p.h | 67 -- src/ktreeview.cpp | 180 ---- src/ktreeview.h | 48 - src/ktreeview_p.h | 49 - src/metadatawidget.cpp | 281 ------ src/metadatawidget.h | 72 -- src/metatextlabel.cpp | 135 --- src/metatextlabel.h | 64 -- src/nepomukmassupdatejob.cpp | 163 ---- src/nepomukmassupdatejob.h | 85 -- .../folders/dolphin_folderspanelsettings.kcfg | 11 + .../folders/dolphin_folderspanelsettings.kcfgc | 4 + src/panels/folders/ktreeview.cpp | 180 ++++ src/panels/folders/ktreeview.h | 48 + src/panels/folders/ktreeview_p.h | 49 + src/panels/folders/sidebartreeview.cpp | 147 +++ src/panels/folders/sidebartreeview.h | 58 ++ src/panels/folders/treeviewcontextmenu.cpp | 194 ++++ src/panels/folders/treeviewcontextmenu.h | 88 ++ src/panels/folders/treeviewsidebarpage.cpp | 279 ++++++ src/panels/folders/treeviewsidebarpage.h | 135 +++ src/panels/information/commenteditwidget.cpp | 241 +++++ src/panels/information/commenteditwidget.h | 62 ++ src/panels/information/commentwidget.cpp | 114 +++ src/panels/information/commentwidget.h | 48 + src/panels/information/infosidebarpage.cpp | 587 ++++++++++++ src/panels/information/infosidebarpage.h | 194 ++++ src/panels/information/metadatawidget.cpp | 281 ++++++ src/panels/information/metadatawidget.h | 72 ++ src/panels/information/metatextlabel.cpp | 135 +++ src/panels/information/metatextlabel.h | 64 ++ src/panels/information/nepomukmassupdatejob.cpp | 163 ++++ src/panels/information/nepomukmassupdatejob.h | 85 ++ src/panels/information/newtagdialog.cpp | 95 ++ src/panels/information/newtagdialog.h | 47 + src/panels/information/newtagdialog.ui | 110 +++ src/panels/information/resourcetaggingwidget.cpp | 193 ++++ src/panels/information/resourcetaggingwidget.h | 63 ++ src/panels/information/tagcloud.cpp | 1005 ++++++++++++++++++++ src/panels/information/tagcloud.h | 142 +++ src/panels/information/taggingpopup.cpp | 147 +++ src/panels/information/taggingpopup.h | 50 + src/panels/places/dolphinfileplacesview.cpp | 56 ++ src/panels/places/dolphinfileplacesview.h | 51 + src/panels/sidebarpage.cpp | 46 + src/panels/sidebarpage.h | 53 ++ src/panels/terminal/terminalsidebarpage.cpp | 97 ++ src/panels/terminal/terminalsidebarpage.h | 62 ++ src/settings/additionalinfodialog.cpp | 102 ++ src/settings/additionalinfodialog.h | 53 ++ src/settings/applyviewpropsjob.cpp | 81 ++ src/settings/applyviewpropsjob.h | 83 ++ src/settings/columnviewsettingspage.cpp | 155 +++ src/settings/columnviewsettingspage.h | 61 ++ src/settings/detailsviewsettingspage.cpp | 147 +++ src/settings/detailsviewsettingspage.h | 60 ++ src/settings/dolphin_columnmodesettings.kcfg | 41 + src/settings/dolphin_columnmodesettings.kcfgc | 4 + src/settings/dolphin_detailsmodesettings.kcfg | 41 + src/settings/dolphin_detailsmodesettings.kcfgc | 4 + .../dolphin_directoryviewpropertysettings.kcfg | 65 ++ .../dolphin_directoryviewpropertysettings.kcfgc | 6 + src/settings/dolphin_generalsettings.kcfg | 71 ++ src/settings/dolphin_generalsettings.kcfgc | 4 + src/settings/dolphin_iconsmodesettings.kcfg | 67 ++ src/settings/dolphin_iconsmodesettings.kcfgc | 4 + src/settings/dolphinfontrequester.cpp | 111 +++ src/settings/dolphinfontrequester.h | 79 ++ src/settings/dolphinsettings.cpp | 78 ++ src/settings/dolphinsettings.h | 92 ++ src/settings/dolphinsettingsdialog.cpp | 114 +++ src/settings/dolphinsettingsdialog.h | 60 ++ src/settings/generalsettingspage.cpp | 170 ++++ src/settings/generalsettingspage.h | 64 ++ src/settings/generalviewsettingspage.cpp | 201 ++++ src/settings/generalviewsettingspage.h | 73 ++ src/settings/iconsizegroupbox.cpp | 116 +++ src/settings/iconsizegroupbox.h | 66 ++ src/settings/iconsviewsettingspage.cpp | 243 +++++ src/settings/iconsviewsettingspage.h | 88 ++ src/settings/settingspagebase.cpp | 31 + src/settings/settingspagebase.h | 56 ++ src/settings/startupsettingspage.cpp | 169 ++++ src/settings/startupsettingspage.h | 66 ++ src/settings/viewpropertiesdialog.cpp | 405 ++++++++ src/settings/viewpropertiesdialog.h | 84 ++ src/settings/viewpropsprogressinfo.cpp | 148 +++ src/settings/viewpropsprogressinfo.h | 78 ++ src/settings/viewsettingspage.cpp | 98 ++ src/settings/viewsettingspage.h | 53 ++ src/settings/viewsettingspagebase.cpp | 31 + src/settings/viewsettingspagebase.h | 55 ++ src/settingspagebase.cpp | 31 - src/settingspagebase.h | 56 -- src/sidebarpage.cpp | 46 - src/sidebarpage.h | 53 -- src/sidebartreeview.cpp | 147 --- src/sidebartreeview.h | 58 -- src/startupsettingspage.cpp | 169 ---- src/startupsettingspage.h | 66 -- src/tagcloud/newtagdialog.cpp | 95 -- src/tagcloud/newtagdialog.h | 47 - src/tagcloud/newtagdialog.ui | 110 --- src/tagcloud/resourcetaggingwidget.cpp | 193 ---- src/tagcloud/resourcetaggingwidget.h | 63 -- src/tagcloud/tagcloud.cpp | 1005 -------------------- src/tagcloud/tagcloud.h | 142 --- src/tagcloud/taggingpopup.cpp | 147 --- src/tagcloud/taggingpopup.h | 50 - src/terminalsidebarpage.cpp | 97 -- src/terminalsidebarpage.h | 62 -- src/tooltipmanager.cpp | 307 ------ src/tooltipmanager.h | 91 -- src/tooltips/dolphintooltip.cpp | 50 + src/tooltips/dolphintooltip.h | 47 + src/tooltips/kformattedballoontipdelegate.cpp | 129 +++ src/tooltips/kformattedballoontipdelegate.h | 45 + src/tooltips/ktooltip.cpp | 558 +++++++++++ src/tooltips/ktooltip.h | 198 ++++ src/tooltips/ktooltip_p.h | 67 ++ src/tooltips/tooltipmanager.cpp | 307 ++++++ src/tooltips/tooltipmanager.h | 91 ++ src/treeviewcontextmenu.cpp | 194 ---- src/treeviewcontextmenu.h | 88 -- src/treeviewsidebarpage.cpp | 279 ------ src/treeviewsidebarpage.h | 135 --- src/viewproperties.cpp | 2 +- src/viewpropertiesdialog.cpp | 405 -------- src/viewpropertiesdialog.h | 84 -- src/viewpropsprogressinfo.cpp | 148 --- src/viewpropsprogressinfo.h | 78 -- src/viewsettingspage.cpp | 98 -- src/viewsettingspage.h | 53 -- src/viewsettingspagebase.cpp | 31 - src/viewsettingspagebase.h | 55 -- 197 files changed, 10909 insertions(+), 10911 deletions(-) delete mode 100644 src/additionalinfodialog.cpp delete mode 100644 src/additionalinfodialog.h delete mode 100644 src/applyviewpropsjob.cpp delete mode 100644 src/applyviewpropsjob.h delete mode 100644 src/columnviewsettingspage.cpp delete mode 100644 src/columnviewsettingspage.h delete mode 100644 src/commenteditwidget.cpp delete mode 100644 src/commenteditwidget.h delete mode 100644 src/commentwidget.cpp delete mode 100644 src/commentwidget.h delete mode 100644 src/detailsviewsettingspage.cpp delete mode 100644 src/detailsviewsettingspage.h delete mode 100644 src/dolphin_columnmodesettings.kcfg delete mode 100644 src/dolphin_columnmodesettings.kcfgc delete mode 100644 src/dolphin_detailsmodesettings.kcfg delete mode 100644 src/dolphin_detailsmodesettings.kcfgc delete mode 100644 src/dolphin_directoryviewpropertysettings.kcfg delete mode 100644 src/dolphin_directoryviewpropertysettings.kcfgc delete mode 100644 src/dolphin_folderspanelsettings.kcfg delete mode 100644 src/dolphin_folderspanelsettings.kcfgc delete mode 100644 src/dolphin_generalsettings.kcfg delete mode 100644 src/dolphin_generalsettings.kcfgc delete mode 100644 src/dolphin_iconsmodesettings.kcfg delete mode 100644 src/dolphin_iconsmodesettings.kcfgc delete mode 100644 src/dolphinfileplacesview.cpp delete mode 100644 src/dolphinfileplacesview.h delete mode 100644 src/dolphinfontrequester.cpp delete mode 100644 src/dolphinfontrequester.h delete mode 100644 src/dolphinsettings.cpp delete mode 100644 src/dolphinsettings.h delete mode 100644 src/dolphinsettingsdialog.cpp delete mode 100644 src/dolphinsettingsdialog.h delete mode 100644 src/dolphintooltip.cpp delete mode 100644 src/dolphintooltip.h delete mode 100644 src/generalsettingspage.cpp delete mode 100644 src/generalsettingspage.h delete mode 100644 src/generalviewsettingspage.cpp delete mode 100644 src/generalviewsettingspage.h delete mode 100644 src/iconsizegroupbox.cpp delete mode 100644 src/iconsizegroupbox.h delete mode 100644 src/iconsviewsettingspage.cpp delete mode 100644 src/iconsviewsettingspage.h delete mode 100644 src/infosidebarpage.cpp delete mode 100644 src/infosidebarpage.h delete mode 100644 src/kformattedballoontipdelegate.cpp delete mode 100644 src/kformattedballoontipdelegate.h delete mode 100644 src/ktooltip.cpp delete mode 100644 src/ktooltip.h delete mode 100644 src/ktooltip_p.h delete mode 100644 src/ktreeview.cpp delete mode 100644 src/ktreeview.h delete mode 100644 src/ktreeview_p.h delete mode 100644 src/metadatawidget.cpp delete mode 100644 src/metadatawidget.h delete mode 100644 src/metatextlabel.cpp delete mode 100644 src/metatextlabel.h delete mode 100644 src/nepomukmassupdatejob.cpp delete mode 100644 src/nepomukmassupdatejob.h create mode 100644 src/panels/folders/dolphin_folderspanelsettings.kcfg create mode 100644 src/panels/folders/dolphin_folderspanelsettings.kcfgc create mode 100644 src/panels/folders/ktreeview.cpp create mode 100644 src/panels/folders/ktreeview.h create mode 100644 src/panels/folders/ktreeview_p.h create mode 100644 src/panels/folders/sidebartreeview.cpp create mode 100644 src/panels/folders/sidebartreeview.h create mode 100644 src/panels/folders/treeviewcontextmenu.cpp create mode 100644 src/panels/folders/treeviewcontextmenu.h create mode 100644 src/panels/folders/treeviewsidebarpage.cpp create mode 100644 src/panels/folders/treeviewsidebarpage.h create mode 100644 src/panels/information/commenteditwidget.cpp create mode 100644 src/panels/information/commenteditwidget.h create mode 100644 src/panels/information/commentwidget.cpp create mode 100644 src/panels/information/commentwidget.h create mode 100644 src/panels/information/infosidebarpage.cpp create mode 100644 src/panels/information/infosidebarpage.h create mode 100644 src/panels/information/metadatawidget.cpp create mode 100644 src/panels/information/metadatawidget.h create mode 100644 src/panels/information/metatextlabel.cpp create mode 100644 src/panels/information/metatextlabel.h create mode 100644 src/panels/information/nepomukmassupdatejob.cpp create mode 100644 src/panels/information/nepomukmassupdatejob.h create mode 100644 src/panels/information/newtagdialog.cpp create mode 100644 src/panels/information/newtagdialog.h create mode 100644 src/panels/information/newtagdialog.ui create mode 100644 src/panels/information/resourcetaggingwidget.cpp create mode 100644 src/panels/information/resourcetaggingwidget.h create mode 100644 src/panels/information/tagcloud.cpp create mode 100644 src/panels/information/tagcloud.h create mode 100644 src/panels/information/taggingpopup.cpp create mode 100644 src/panels/information/taggingpopup.h create mode 100644 src/panels/places/dolphinfileplacesview.cpp create mode 100644 src/panels/places/dolphinfileplacesview.h create mode 100644 src/panels/sidebarpage.cpp create mode 100644 src/panels/sidebarpage.h create mode 100644 src/panels/terminal/terminalsidebarpage.cpp create mode 100644 src/panels/terminal/terminalsidebarpage.h create mode 100644 src/settings/additionalinfodialog.cpp create mode 100644 src/settings/additionalinfodialog.h create mode 100644 src/settings/applyviewpropsjob.cpp create mode 100644 src/settings/applyviewpropsjob.h create mode 100644 src/settings/columnviewsettingspage.cpp create mode 100644 src/settings/columnviewsettingspage.h create mode 100644 src/settings/detailsviewsettingspage.cpp create mode 100644 src/settings/detailsviewsettingspage.h create mode 100644 src/settings/dolphin_columnmodesettings.kcfg create mode 100644 src/settings/dolphin_columnmodesettings.kcfgc create mode 100644 src/settings/dolphin_detailsmodesettings.kcfg create mode 100644 src/settings/dolphin_detailsmodesettings.kcfgc create mode 100644 src/settings/dolphin_directoryviewpropertysettings.kcfg create mode 100644 src/settings/dolphin_directoryviewpropertysettings.kcfgc create mode 100644 src/settings/dolphin_generalsettings.kcfg create mode 100644 src/settings/dolphin_generalsettings.kcfgc create mode 100644 src/settings/dolphin_iconsmodesettings.kcfg create mode 100644 src/settings/dolphin_iconsmodesettings.kcfgc create mode 100644 src/settings/dolphinfontrequester.cpp create mode 100644 src/settings/dolphinfontrequester.h create mode 100644 src/settings/dolphinsettings.cpp create mode 100644 src/settings/dolphinsettings.h create mode 100644 src/settings/dolphinsettingsdialog.cpp create mode 100644 src/settings/dolphinsettingsdialog.h create mode 100644 src/settings/generalsettingspage.cpp create mode 100644 src/settings/generalsettingspage.h create mode 100644 src/settings/generalviewsettingspage.cpp create mode 100644 src/settings/generalviewsettingspage.h create mode 100644 src/settings/iconsizegroupbox.cpp create mode 100644 src/settings/iconsizegroupbox.h create mode 100644 src/settings/iconsviewsettingspage.cpp create mode 100644 src/settings/iconsviewsettingspage.h create mode 100644 src/settings/settingspagebase.cpp create mode 100644 src/settings/settingspagebase.h create mode 100644 src/settings/startupsettingspage.cpp create mode 100644 src/settings/startupsettingspage.h create mode 100644 src/settings/viewpropertiesdialog.cpp create mode 100644 src/settings/viewpropertiesdialog.h create mode 100644 src/settings/viewpropsprogressinfo.cpp create mode 100644 src/settings/viewpropsprogressinfo.h create mode 100644 src/settings/viewsettingspage.cpp create mode 100644 src/settings/viewsettingspage.h create mode 100644 src/settings/viewsettingspagebase.cpp create mode 100644 src/settings/viewsettingspagebase.h delete mode 100644 src/settingspagebase.cpp delete mode 100644 src/settingspagebase.h delete mode 100644 src/sidebarpage.cpp delete mode 100644 src/sidebarpage.h delete mode 100644 src/sidebartreeview.cpp delete mode 100644 src/sidebartreeview.h delete mode 100644 src/startupsettingspage.cpp delete mode 100644 src/startupsettingspage.h delete mode 100644 src/tagcloud/newtagdialog.cpp delete mode 100644 src/tagcloud/newtagdialog.h delete mode 100644 src/tagcloud/newtagdialog.ui delete mode 100644 src/tagcloud/resourcetaggingwidget.cpp delete mode 100644 src/tagcloud/resourcetaggingwidget.h delete mode 100644 src/tagcloud/tagcloud.cpp delete mode 100644 src/tagcloud/tagcloud.h delete mode 100644 src/tagcloud/taggingpopup.cpp delete mode 100644 src/tagcloud/taggingpopup.h delete mode 100644 src/terminalsidebarpage.cpp delete mode 100644 src/terminalsidebarpage.h delete mode 100644 src/tooltipmanager.cpp delete mode 100644 src/tooltipmanager.h create mode 100644 src/tooltips/dolphintooltip.cpp create mode 100644 src/tooltips/dolphintooltip.h create mode 100644 src/tooltips/kformattedballoontipdelegate.cpp create mode 100644 src/tooltips/kformattedballoontipdelegate.h create mode 100644 src/tooltips/ktooltip.cpp create mode 100644 src/tooltips/ktooltip.h create mode 100644 src/tooltips/ktooltip_p.h create mode 100644 src/tooltips/tooltipmanager.cpp create mode 100644 src/tooltips/tooltipmanager.h delete mode 100644 src/treeviewcontextmenu.cpp delete mode 100644 src/treeviewcontextmenu.h delete mode 100644 src/treeviewsidebarpage.cpp delete mode 100644 src/treeviewsidebarpage.h delete mode 100644 src/viewpropertiesdialog.cpp delete mode 100644 src/viewpropertiesdialog.h delete mode 100644 src/viewpropsprogressinfo.cpp delete mode 100644 src/viewpropsprogressinfo.h delete mode 100644 src/viewsettingspage.cpp delete mode 100644 src/viewsettingspage.h delete mode 100644 src/viewsettingspagebase.cpp delete mode 100644 src/viewsettingspagebase.h (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9cd091045..708271d00 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -18,8 +18,8 @@ endif (Nepomuk_FOUND) ########### next target ############### set(dolphinprivate_LIB_SRCS - additionalinfodialog.cpp - applyviewpropsjob.cpp + settings/additionalinfodialog.cpp + settings/applyviewpropsjob.cpp dolphincontroller.cpp dolphindetailsview.cpp dolphiniconsview.cpp @@ -28,33 +28,33 @@ set(dolphinprivate_LIB_SRCS dolphindirlister.cpp dolphinfileitemdelegate.cpp dolphinmodel.cpp - dolphinsettings.cpp + settings/dolphinsettings.cpp dolphinsortfilterproxymodel.cpp - dolphintooltip.cpp + tooltips/dolphintooltip.cpp dolphincategorydrawer.cpp dolphinview.cpp dolphinviewactionhandler.cpp dolphinviewautoscroller.cpp draganddrophelper.cpp folderexpander.cpp - ktooltip.cpp - kformattedballoontipdelegate.cpp + tooltips/ktooltip.cpp + tooltips/kformattedballoontipdelegate.cpp renamedialog.cpp selectiontoggle.cpp selectionmanager.cpp - tooltipmanager.cpp + tooltips/tooltipmanager.cpp viewproperties.cpp - viewpropertiesdialog.cpp - viewpropsprogressinfo.cpp + settings/viewpropertiesdialog.cpp + settings/viewpropsprogressinfo.cpp zoomlevelinfo.cpp ) kde4_add_kcfg_files(dolphinprivate_LIB_SRCS - dolphin_columnmodesettings.kcfgc - dolphin_directoryviewpropertysettings.kcfgc - dolphin_detailsmodesettings.kcfgc - dolphin_iconsmodesettings.kcfgc - dolphin_generalsettings.kcfgc) + settings/dolphin_columnmodesettings.kcfgc + settings/dolphin_directoryviewpropertysettings.kcfgc + settings/dolphin_detailsmodesettings.kcfgc + settings/dolphin_iconsmodesettings.kcfgc + settings/dolphin_generalsettings.kcfgc) kde4_add_library(dolphinprivate SHARED ${dolphinprivate_LIB_SRCS}) @@ -90,62 +90,62 @@ install(FILES dolphinpart.desktop DESTINATION ${SERVICES_INSTALL_DIR} ) ########################################## set(dolphin_SRCS - columnviewsettingspage.cpp - commentwidget.cpp - commenteditwidget.cpp - detailsviewsettingspage.cpp + settings/columnviewsettingspage.cpp + panels/information/commentwidget.cpp + panels/information/commenteditwidget.cpp + settings/detailsviewsettingspage.cpp dolphinapplication.cpp - dolphinfontrequester.cpp + settings/dolphinfontrequester.cpp dolphinmainwindow.cpp dolphinnewmenu.cpp dolphinviewcontainer.cpp dolphinstatusbar.cpp dolphindirlister.cpp dolphincontextmenu.cpp - dolphinfileplacesview.cpp - dolphinsettingsdialog.cpp + panels/places/dolphinfileplacesview.cpp + settings/dolphinsettingsdialog.cpp filterbar.cpp - generalsettingspage.cpp - generalviewsettingspage.cpp - iconsizegroupbox.cpp - iconsviewsettingspage.cpp - infosidebarpage.cpp - ktreeview.cpp + settings/generalsettingspage.cpp + settings/generalviewsettingspage.cpp + settings/iconsizegroupbox.cpp + settings/iconsviewsettingspage.cpp + panels/information/infosidebarpage.cpp + panels/folders/ktreeview.cpp main.cpp - metadatawidget.cpp - metatextlabel.cpp + panels/information/metadatawidget.cpp + panels/information/metatextlabel.cpp pixmapviewer.cpp - settingspagebase.cpp - sidebarpage.cpp - startupsettingspage.cpp + settings/settingspagebase.cpp + panels/sidebarpage.cpp + settings/startupsettingspage.cpp statusbarspaceinfo.cpp statusbarmessagelabel.cpp - treeviewcontextmenu.cpp - treeviewsidebarpage.cpp - sidebartreeview.cpp - viewsettingspage.cpp - viewsettingspagebase.cpp + panels/folders/treeviewcontextmenu.cpp + panels/folders/treeviewsidebarpage.cpp + panels/folders/sidebartreeview.cpp + settings/viewsettingspage.cpp + settings/viewsettingspagebase.cpp zoomlevelinfo.cpp ) kde4_add_kcfg_files(dolphin_SRCS - dolphin_folderspanelsettings.kcfgc) + panels/folders/dolphin_folderspanelsettings.kcfgc) if(Nepomuk_FOUND) set(dolphin_SRCS ${dolphin_SRCS} - nepomukmassupdatejob.cpp - tagcloud/tagcloud.cpp - tagcloud/resourcetaggingwidget.cpp - tagcloud/taggingpopup.cpp - tagcloud/newtagdialog.cpp + panels/information/nepomukmassupdatejob.cpp + panels/information/tagcloud.cpp + panels/information/resourcetaggingwidget.cpp + panels/information/taggingpopup.cpp + panels/information/newtagdialog.cpp ) -kde4_add_ui_files(dolphin_SRCS tagcloud/newtagdialog.ui) +kde4_add_ui_files(dolphin_SRCS panels/information/newtagdialog.ui) endif(Nepomuk_FOUND) if(NOT WIN32) - set(dolphin_SRCS ${dolphin_SRCS} terminalsidebarpage.cpp) + set(dolphin_SRCS ${dolphin_SRCS} panels/terminal/terminalsidebarpage.cpp) endif(NOT WIN32) qt4_add_dbus_adaptor(dolphin_SRCS @@ -171,25 +171,23 @@ install(TARGETS dolphin ${INSTALL_TARGETS_DEFAULT_ARGS}) set(kcm_dolphin_PART_SRCS kcmdolphin.cpp - columnviewsettingspage.cpp - detailsviewsettingspage.cpp - dolphinfontrequester.cpp -# dolphinsettings.cpp - generalviewsettingspage.cpp - iconsizegroupbox.cpp - iconsviewsettingspage.cpp + settings/columnviewsettingspage.cpp + settings/detailsviewsettingspage.cpp + settings/dolphinfontrequester.cpp + settings/generalviewsettingspage.cpp + settings/iconsizegroupbox.cpp + settings/iconsviewsettingspage.cpp pixmapviewer.cpp - viewsettingspagebase.cpp -# viewproperties.cpp + settings/viewsettingspagebase.cpp zoomlevelinfo.cpp ) kde4_add_kcfg_files(kcm_dolphin_PART_SRCS - dolphin_columnmodesettings.kcfgc - dolphin_directoryviewpropertysettings.kcfgc - dolphin_detailsmodesettings.kcfgc - dolphin_iconsmodesettings.kcfgc - dolphin_generalsettings.kcfgc) + settings/dolphin_columnmodesettings.kcfgc + settings/dolphin_directoryviewpropertysettings.kcfgc + settings/dolphin_detailsmodesettings.kcfgc + settings/dolphin_iconsmodesettings.kcfgc + settings/dolphin_generalsettings.kcfgc) kde4_add_plugin(kcm_dolphin ${kcm_dolphin_PART_SRCS}) @@ -203,6 +201,6 @@ install(TARGETS kcm_dolphin DESTINATION ${PLUGIN_INSTALL_DIR} ) ########### install files ############### install( FILES dolphin.desktop DESTINATION ${XDG_APPS_INSTALL_DIR} ) -install( FILES dolphin_directoryviewpropertysettings.kcfg dolphin_generalsettings.kcfg dolphin_columnmodesettings.kcfg dolphin_iconsmodesettings.kcfg dolphin_detailsmodesettings.kcfg DESTINATION ${KCFG_INSTALL_DIR} ) +install( FILES settings/dolphin_directoryviewpropertysettings.kcfg settings/dolphin_generalsettings.kcfg settings/dolphin_columnmodesettings.kcfg settings/dolphin_iconsmodesettings.kcfg settings/dolphin_detailsmodesettings.kcfg DESTINATION ${KCFG_INSTALL_DIR} ) install( FILES dolphinui.rc DESTINATION ${DATA_INSTALL_DIR}/dolphin ) install( FILES kcmdolphin.desktop DESTINATION ${SERVICES_INSTALL_DIR} ) diff --git a/src/additionalinfodialog.cpp b/src/additionalinfodialog.cpp deleted file mode 100644 index 2f735fffe..000000000 --- a/src/additionalinfodialog.cpp +++ /dev/null @@ -1,102 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2007 by Peter Penz (peter.penz@gmx.at) * - * * - * 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 of the License, 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. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#include "additionalinfodialog.h" - -#include -#include - -#include - -AdditionalInfoDialog::AdditionalInfoDialog(QWidget* parent, - KFileItemDelegate::InformationList info) : - KDialog(parent), - m_info(info), - m_size(0), - m_date(0), - m_permissions(0), - m_owner(0), - m_group(0), - m_type(0) -{ - setCaption(i18nc("@title:window", "Additional Information")); - setButtons(Ok | Cancel); - setDefaultButton(Ok); - - KVBox* box = new KVBox(this); - - m_size = new QCheckBox(i18nc("@option:check Additional Information", "Size"), box); - m_date = new QCheckBox(i18nc("@option:check Additional Information", "Date"), box); - m_permissions = new QCheckBox(i18nc("@option:check Additional Information", "Permissions"), box); - m_owner = new QCheckBox(i18nc("@option:check Additional Information", "Owner"), box); - m_group = new QCheckBox(i18nc("@option:check Additional Information", "Group"), box); - m_type = new QCheckBox(i18nc("@option:check Additional Information", "Type"), box); - connect(this, SIGNAL(okClicked()), this, SLOT(slotOk())); - - m_size->setChecked(info.contains(KFileItemDelegate::Size)); - m_date->setChecked(info.contains(KFileItemDelegate::ModificationTime)); - m_permissions->setChecked(info.contains(KFileItemDelegate::Permissions)); - m_owner->setChecked(info.contains(KFileItemDelegate::Owner)); - m_group->setChecked(info.contains(KFileItemDelegate::OwnerAndGroup)); - m_type->setChecked(info.contains(KFileItemDelegate::FriendlyMimeType)); - - setMainWidget(box); - - const KConfigGroup dialogConfig(KSharedConfig::openConfig("dolphinrc"), - "AdditionalInfoDialog"); - restoreDialogSize(dialogConfig); -} - -AdditionalInfoDialog::~AdditionalInfoDialog() -{ - KConfigGroup dialogConfig(KSharedConfig::openConfig("dolphinrc"), - "AdditionalInfoDialog"); - saveDialogSize(dialogConfig, KConfigBase::Persistent); -} - -KFileItemDelegate::InformationList AdditionalInfoDialog::additionalInfo() const -{ - return m_info; -} - -void AdditionalInfoDialog::slotOk() -{ - m_info.clear(); - - if (m_size->isChecked()) { - m_info.append(KFileItemDelegate::Size); - } - if (m_date->isChecked()) { - m_info.append(KFileItemDelegate::ModificationTime); - } - if (m_permissions->isChecked()) { - m_info.append(KFileItemDelegate::Permissions); - } - if (m_owner->isChecked()) { - m_info.append(KFileItemDelegate::Owner); - } - if (m_group->isChecked()) { - m_info.append(KFileItemDelegate::OwnerAndGroup); - } - if (m_type->isChecked()) { - m_info.append(KFileItemDelegate::FriendlyMimeType); - } -} - -#include "additionalinfodialog.moc" diff --git a/src/additionalinfodialog.h b/src/additionalinfodialog.h deleted file mode 100644 index 9771960f0..000000000 --- a/src/additionalinfodialog.h +++ /dev/null @@ -1,53 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2007 by Peter Penz (peter.penz@gmx.at) * - * * - * 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 of the License, 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. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#ifndef ADDITIONALINFODIALOG_H -#define ADDITIONALINFODIALOG_H - -#include -#include - -class QCheckBox; - -/** - * @brief Dialog for changing the additional information properties of a directory. - */ -class AdditionalInfoDialog : public KDialog -{ - Q_OBJECT - -public: - explicit AdditionalInfoDialog(QWidget* parent, KFileItemDelegate::InformationList info); - virtual ~AdditionalInfoDialog(); - KFileItemDelegate::InformationList additionalInfo() const; - -private slots: - void slotOk(); - -private: - KFileItemDelegate::InformationList m_info; - QCheckBox* m_size; - QCheckBox* m_date; - QCheckBox* m_permissions; - QCheckBox* m_owner; - QCheckBox* m_group; - QCheckBox* m_type; -}; - -#endif diff --git a/src/applyviewpropsjob.cpp b/src/applyviewpropsjob.cpp deleted file mode 100644 index 9250226e9..000000000 --- a/src/applyviewpropsjob.cpp +++ /dev/null @@ -1,81 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2006 by Peter Penz * - * * - * The code is based on kdelibs/kio/directorysizejob.* * - * (C) 2006 by David Faure * - * * - * 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 of the License, 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. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#include "applyviewpropsjob.h" -#include "viewproperties.h" - -ApplyViewPropsJob::ApplyViewPropsJob(const KUrl& dir, - const ViewProperties& viewProps) : - KIO::Job(), - m_viewProps(0), - m_progress(0), - m_dir(dir) -{ - m_viewProps = new ViewProperties(dir); - m_viewProps->setViewMode(viewProps.viewMode()); - m_viewProps->setShowPreview(viewProps.showPreview()); - m_viewProps->setShowHiddenFiles(viewProps.showHiddenFiles()); - m_viewProps->setSorting(viewProps.sorting()); - m_viewProps->setSortOrder(viewProps.sortOrder()); - - KIO::ListJob* listJob = KIO::listRecursive(dir, KIO::HideProgressInfo); - connect(listJob, SIGNAL(entries(KIO::Job*, const KIO::UDSEntryList&)), - SLOT(slotEntries(KIO::Job*, const KIO::UDSEntryList&))); - addSubjob(listJob); -} - -ApplyViewPropsJob::~ApplyViewPropsJob() -{ - delete m_viewProps; // the properties are written by the destructor - m_viewProps = 0; -} - -void ApplyViewPropsJob::slotEntries(KIO::Job*, const KIO::UDSEntryList& list) -{ - KIO::UDSEntryList::ConstIterator it = list.begin(); - const KIO::UDSEntryList::ConstIterator end = list.end(); - foreach(const KIO::UDSEntry& entry, list) { - const QString name = entry.stringValue(KIO::UDSEntry::UDS_NAME); - if ((name != ".") && (name != "..") && entry.isDir()) { - ++m_progress; - - KUrl url(m_dir); - url.addPath(name); - - Q_ASSERT(m_viewProps != 0); - - ViewProperties props(url); - props.setDirProperties(*m_viewProps); - } - } -} - -void ApplyViewPropsJob::slotResult(KJob* job) -{ - if (job->error()) { - setError(job->error()); - setErrorText(job->errorText()); - } - emitResult(); -} - -#include "applyviewpropsjob.moc" diff --git a/src/applyviewpropsjob.h b/src/applyviewpropsjob.h deleted file mode 100644 index da18af966..000000000 --- a/src/applyviewpropsjob.h +++ /dev/null @@ -1,83 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2006 by Peter Penz * - * * - * The code is based on kdelibs/kio/kio/directorysizejob.* * - * (C) 2006 by David Faure * - * * - * 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 of the License, 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. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#ifndef APPLYVIEWPROPSJOB_H -#define APPLYVIEWPROPSJOB_H - -#include -#include -#include - -class ViewProperties; - -/** - * @brief Applies view properties recursively to directories. - * - * Usage: - * \code - * KJob* job = new ApplyViewPropsJob(dir, viewProps); - * connect(job, SIGNAL(result(KJob*)), - * this, SLOT(slotResult(KJob*))); - * \endcode - * - * To be able to show a progress of the operation, the following steps - * are recommended: - * - Use a DirectorySizeJob to count the number of directories. - * - Use a timer to show the current count of directories by invoking - * DirectorySizeJob::totalSubdirs() until the result signal is emitted. - * - Use the ApplyViewPropsJob. - * - Use a timer to show the progress by invoking ApplyViwePropsJob::progress(). - * In combination with the total directory count it is possible to show a - * progress bar now. - */ -class ApplyViewPropsJob : public KIO::Job -{ - Q_OBJECT - -public: - /** - * @param dir Directory where the view properties should be applied to - * (including sub directories). - * @param viewProps View properties for the directory \a dir including its - * sub directories. - */ - ApplyViewPropsJob(const KUrl& dir, const ViewProperties& viewProps); - virtual ~ApplyViewPropsJob(); - int progress() const; - -private slots: - virtual void slotResult(KJob* job); - void slotEntries(KIO::Job*, const KIO::UDSEntryList&); - -private: - ViewProperties* m_viewProps; - int m_currentItem; - int m_progress; - KUrl m_dir; -}; - -inline int ApplyViewPropsJob::progress() const -{ - return m_progress; -} - -#endif diff --git a/src/columnviewsettingspage.cpp b/src/columnviewsettingspage.cpp deleted file mode 100644 index 5918eaf92..000000000 --- a/src/columnviewsettingspage.cpp +++ /dev/null @@ -1,155 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2006 by Peter Penz * - * * - * 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 of the License, 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. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#include "columnviewsettingspage.h" - -#include "dolphinfontrequester.h" -#include "dolphinsettings.h" -#include "dolphin_columnmodesettings.h" -#include "iconsizegroupbox.h" -#include "zoomlevelinfo.h" - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -ColumnViewSettingsPage::ColumnViewSettingsPage(QWidget* parent) : - ViewSettingsPageBase(parent), - m_iconSizeGroupBox(0), - m_fontRequester(0), - m_textWidthBox(0) -{ - const int spacing = KDialog::spacingHint(); - const int margin = KDialog::marginHint(); - const QSizePolicy sizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); - - setSpacing(spacing); - setMargin(margin); - - // Create "Icon" properties - m_iconSizeGroupBox = new IconSizeGroupBox(this); - m_iconSizeGroupBox->setSizePolicy(sizePolicy); - - const int min = ZoomLevelInfo::minimumLevel(); - const int max = ZoomLevelInfo::maximumLevel(); - m_iconSizeGroupBox->setDefaultSizeRange(min, max); - m_iconSizeGroupBox->setPreviewSizeRange(min, max); - - connect(m_iconSizeGroupBox, SIGNAL(defaultSizeChanged(int)), - this, SIGNAL(changed())); - connect(m_iconSizeGroupBox, SIGNAL(previewSizeChanged(int)), - this, SIGNAL(changed())); - - // create "Text" properties - QGroupBox* textGroup = new QGroupBox(i18nc("@title:group", "Text"), this); - textGroup->setSizePolicy(sizePolicy); - - QLabel* fontLabel = new QLabel(i18nc("@label:listbox", "Font:"), textGroup); - m_fontRequester = new DolphinFontRequester(textGroup); - connect(m_fontRequester, SIGNAL(changed()), this, SIGNAL(changed())); - - QLabel* textWidthLabel = new QLabel(i18nc("@label:listbox", "Text width:"), textGroup); - m_textWidthBox = new KComboBox(textGroup); - m_textWidthBox->addItem(i18nc("@item:inlistbox Text width", "Small")); - m_textWidthBox->addItem(i18nc("@item:inlistbox Text width", "Medium")); - m_textWidthBox->addItem(i18nc("@item:inlistbox Text width", "Large")); - connect(m_textWidthBox, SIGNAL(activated(int)), this, SIGNAL(changed())); - - QGridLayout* textGroupLayout = new QGridLayout(textGroup); - textGroupLayout->addWidget(fontLabel, 0, 0, Qt::AlignRight); - textGroupLayout->addWidget(m_fontRequester, 0, 1); - textGroupLayout->addWidget(textWidthLabel, 1, 0, Qt::AlignRight); - textGroupLayout->addWidget(m_textWidthBox, 1, 1); - - // Add a dummy widget with no restriction regarding - // a vertical resizing. This assures that the dialog layout - // is not stretched vertically. - new QWidget(this); - - loadSettings(); -} - -ColumnViewSettingsPage::~ColumnViewSettingsPage() -{ -} - -void ColumnViewSettingsPage::applySettings() -{ - ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings(); - - const int iconSize = ZoomLevelInfo::iconSizeForZoomLevel(m_iconSizeGroupBox->defaultSizeValue()); - const int previewSize = ZoomLevelInfo::iconSizeForZoomLevel(m_iconSizeGroupBox->previewSizeValue()); - settings->setIconSize(iconSize); - settings->setPreviewSize(previewSize); - - const QFont font = m_fontRequester->font(); - settings->setUseSystemFont(m_fontRequester->mode() == DolphinFontRequester::SystemFont); - settings->setFontFamily(font.family()); - settings->setFontSize(font.pointSize()); - settings->setItalicFont(font.italic()); - settings->setFontWeight(font.weight()); - - // TODO: - //const int columnWidth = 150 + (m_columnWidthSlider->value() * 50); - //settings->setColumnWidth(columnWidth); -} - -void ColumnViewSettingsPage::restoreDefaults() -{ - ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings(); - settings->setDefaults(); - loadSettings(); -} - -void ColumnViewSettingsPage::loadSettings() -{ - ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings(); - - const QSize iconSize(settings->iconSize(), settings->iconSize()); - const int iconSizeValue = ZoomLevelInfo::zoomLevelForIconSize(iconSize); - m_iconSizeGroupBox->setDefaultSizeValue(iconSizeValue); - - const QSize previewSize(settings->previewSize(), settings->previewSize()); - const int previewSizeValue = ZoomLevelInfo::zoomLevelForIconSize(previewSize); - m_iconSizeGroupBox->setPreviewSizeValue(previewSizeValue); - - if (settings->useSystemFont()) { - m_fontRequester->setMode(DolphinFontRequester::SystemFont); - } else { - QFont font(settings->fontFamily(), - settings->fontSize()); - font.setItalic(settings->italicFont()); - font.setWeight(settings->fontWeight()); - m_fontRequester->setMode(DolphinFontRequester::CustomFont); - m_fontRequester->setCustomFont(font); - } - - // TODO: - //m_columnWidthSlider->setValue((settings->columnWidth() - 150) / 50); -} - -#include "columnviewsettingspage.moc" diff --git a/src/columnviewsettingspage.h b/src/columnviewsettingspage.h deleted file mode 100644 index 5e16dc67b..000000000 --- a/src/columnviewsettingspage.h +++ /dev/null @@ -1,61 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2006 by Peter Penz * - * * - * 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 of the License, 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. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#ifndef COLUMNVIEWSETTINGSPAGE_H -#define COLUMNVIEWSETTINGSPAGE_H - -#include - -class DolphinMainWindow; -class DolphinFontRequester; -class IconSizeGroupBox; -class KComboBox; - -/** - * @brief Represents the page from the Dolphin Settings which allows - * to modify the settings for the details view. - */ -class ColumnViewSettingsPage : public ViewSettingsPageBase -{ - Q_OBJECT - -public: - ColumnViewSettingsPage(QWidget* parent); - virtual ~ColumnViewSettingsPage(); - - /** - * Applies the settings for the details view. - * The settings are persisted automatically when - * closing Dolphin. - */ - virtual void applySettings(); - - /** Restores the settings to default values. */ - virtual void restoreDefaults(); - -private: - void loadSettings(); - -private: - IconSizeGroupBox* m_iconSizeGroupBox; - DolphinFontRequester* m_fontRequester; - KComboBox* m_textWidthBox; -}; - -#endif diff --git a/src/commenteditwidget.cpp b/src/commenteditwidget.cpp deleted file mode 100644 index a55adbea4..000000000 --- a/src/commenteditwidget.cpp +++ /dev/null @@ -1,241 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Sebastian Trueg * - * * - * 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 of the License, 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. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#include "commenteditwidget.h" - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - - -class CommentEditWidget::Private -{ -public: - Private( CommentEditWidget* parent ) - : eventLoop( 0 ), - q( parent ) { - } - - QEventLoop* eventLoop; - bool success; - KTextEdit* textEdit; - QToolButton* buttonSave; - QToolButton* buttonCancel; - - QString comment; - - QRect geometryForPopupPos( const QPoint& p ) { - QSize size = q->sizeHint(); - - // we want a little margin - const int margin = KDialog::marginHint(); - size.setHeight( size.height() + margin*2 ); - size.setWidth( size.width() + margin*2 ); - - QRect screen = QApplication::desktop()->screenGeometry( QApplication::desktop()->screenNumber( p ) ); - - // calculate popup position - QPoint pos( p.x() - size.width()/2, p.y() - size.height()/2 ); - - // ensure we do not leave the desktop - if ( pos.x() + size.width() > screen.right() ) { - pos.setX( screen.right() - size.width() ); - } - else if ( pos.x() < screen.left() ) { - pos.setX( screen.left() ); - } - - if ( pos.y() + size.height() > screen.bottom() ) { - pos.setY( screen.bottom() - size.height() ); - } - else if ( pos.y() < screen.top() ) { - pos.setY( screen.top() ); - } - - return QRect( pos, size ); - } - - void _k_saveClicked(); - void _k_cancelClicked(); - -private: - CommentEditWidget* q; -}; - - -void CommentEditWidget::Private::_k_saveClicked() -{ - comment = textEdit->toPlainText(); - success = true; - q->hide(); -} - - -void CommentEditWidget::Private::_k_cancelClicked() -{ - success = false; - q->hide(); -} - - -CommentEditWidget::CommentEditWidget( QWidget* parent ) - : QFrame( parent ), - d( new Private( this ) ) -{ - setFrameStyle( QFrame::Box|QFrame::Plain ); - setWindowFlags( Qt::Popup ); - - d->textEdit = new KTextEdit( this ); - d->textEdit->installEventFilter( this ); - QVBoxLayout* layout = new QVBoxLayout( this ); - layout->setMargin( 0 ); - layout->addWidget( d->textEdit ); - - d->buttonSave = new QToolButton( d->textEdit ); - d->buttonCancel = new QToolButton( d->textEdit ); - d->buttonSave->setToolButtonStyle( Qt::ToolButtonTextBesideIcon ); - d->buttonCancel->setToolButtonStyle( Qt::ToolButtonTextBesideIcon ); - d->buttonSave->setAutoRaise( true ); - d->buttonCancel->setAutoRaise( true ); - d->buttonSave->setIcon( KIcon( "document-save" ) ); - d->buttonCancel->setIcon( KIcon( "edit-delete" ) ); - d->buttonSave->setText( i18nc( "@action:button", "Save" ) ); - d->buttonCancel->setText( i18nc( "@action:button", "Cancel" ) ); - - QFont fnt( font() ); - fnt.setPointSize( fnt.pointSize()-2 ); - d->buttonSave->setFont( fnt ); - d->buttonCancel->setFont( fnt ); - - connect( d->buttonSave, SIGNAL(clicked()), - this, SLOT( _k_saveClicked() ) ); - connect( d->buttonCancel, SIGNAL(clicked()), - this, SLOT( _k_cancelClicked() ) ); -} - - -CommentEditWidget::~CommentEditWidget() -{ - delete d; -} - - -void CommentEditWidget::setComment( const QString& s ) -{ - d->comment = s; -} - - -QString CommentEditWidget::comment() -{ - return d->comment; -} - - -bool CommentEditWidget::exec( const QPoint& pos ) -{ - d->success = false; - d->textEdit->setPlainText( d->comment ); - d->textEdit->setFocus(); - d->textEdit->moveCursor( QTextCursor::End ); - QEventLoop eventLoop; - d->eventLoop = &eventLoop; - setGeometry( d->geometryForPopupPos( pos ) ); - show(); - - QPointer guard = this; - (void) eventLoop.exec(); - if ( !guard.isNull() ) - d->eventLoop = 0; - return d->success; -} - - -void CommentEditWidget::mousePressEvent( QMouseEvent* e ) -{ - // clicking outside of the widget means cancel - if ( !rect().contains( e->pos() ) ) { - d->success = false; - hide(); - } - else { - QWidget::mousePressEvent( e ); - } -} - - -void CommentEditWidget::hideEvent( QHideEvent* e ) -{ - Q_UNUSED( e ); - if ( d->eventLoop ) { - d->eventLoop->exit(); - } -} - - -void CommentEditWidget::updateButtons() -{ - QSize sbs = d->buttonSave->sizeHint(); - QSize cbs = d->buttonCancel->sizeHint(); - - // FIXME: button order - d->buttonCancel->setGeometry( QRect( QPoint( d->textEdit->width() - cbs.width() - frameWidth(), - d->textEdit->height() - cbs.height() - frameWidth() ), - cbs ) ); - d->buttonSave->setGeometry( QRect( QPoint( d->textEdit->width() - cbs.width() - sbs.width() - frameWidth(), - d->textEdit->height() - sbs.height() - frameWidth() ), - sbs ) ); -} - - -void CommentEditWidget::resizeEvent( QResizeEvent* e ) -{ - QWidget::resizeEvent( e ); - updateButtons(); -} - - -bool CommentEditWidget::eventFilter( QObject* watched, QEvent* event ) -{ - if ( watched == d->textEdit && event->type() == QEvent::KeyPress ) { - QKeyEvent* ke = static_cast( event ); - kDebug() << "keypress:" << ke->key() << ke->modifiers(); - if ( ( ke->key() == Qt::Key_Enter || - ke->key() == Qt::Key_Return ) && - ke->modifiers() & Qt::ControlModifier ) { - d->_k_saveClicked(); - return true; - } - } - - return QFrame::eventFilter( watched, event ); -} - -#include "commenteditwidget.moc" diff --git a/src/commenteditwidget.h b/src/commenteditwidget.h deleted file mode 100644 index 18ab8d7b2..000000000 --- a/src/commenteditwidget.h +++ /dev/null @@ -1,62 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Sebastian Trueg * - * * - * 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 of the License, 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. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#ifndef _COMMENT_EDIT_WIDGET_H_ -#define _COMMENT_EDIT_WIDGET_H_ - -#include - -class QResizeEvent; -class QMouseEvent; -class QHideEvent; - -class CommentEditWidget : public QFrame -{ - Q_OBJECT - -public: - CommentEditWidget( QWidget* parent = 0 ); - ~CommentEditWidget(); - - void setComment( const QString& s ); - QString comment(); - - /** - * Show the comment widget at position pos. - * \return true if the user chose to save the comment, - * false otherwise. - */ - bool exec( const QPoint& pos ); - - bool eventFilter( QObject* watched, QEvent* event ); - -private: - void updateButtons(); - void resizeEvent( QResizeEvent* ); - void mousePressEvent( QMouseEvent* e ); - void hideEvent( QHideEvent* e ); - - class Private; - Private* const d; - - Q_PRIVATE_SLOT( d, void _k_saveClicked() ) - Q_PRIVATE_SLOT( d, void _k_cancelClicked() ) -}; - -#endif diff --git a/src/commentwidget.cpp b/src/commentwidget.cpp deleted file mode 100644 index 586be63aa..000000000 --- a/src/commentwidget.cpp +++ /dev/null @@ -1,114 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Sebastian Trueg * - * * - * 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 of the License, 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. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#include "commentwidget.h" -#include "commenteditwidget.h" - -#include -#include -#include -#include -#include - -#include - - -class CommentWidget::Private -{ -public: - Private( CommentWidget* parent ) - : q( parent ) { - } - - void update(); - void _k_slotEnableEditing(); - - QLabel* label; - CommentEditWidget* edit; - - QString comment; - -private: - CommentWidget* q; -}; - - -void CommentWidget::Private::update() -{ - if ( comment.isEmpty() ) { - label->setText( "

" + i18nc( "@label", "Add Comment..." ) + "" ); - } - else { - label->setText( "

" + comment + "

" + i18nc( "@label", "Change Comment..." ) + "" ); - } -} - - -void CommentWidget::Private::_k_slotEnableEditing() -{ - CommentEditWidget w; - w.setComment( comment ); - if ( w.exec( QCursor::pos() ) ) { - comment = w.comment(); - update(); - emit q->commentChanged( comment ); - } -} - - - -CommentWidget::CommentWidget( QWidget* parent ) - : QWidget( parent ), - d( new Private( this ) ) -{ - d->label = new QLabel( this ); - d->label->setWordWrap( true ); - QVBoxLayout* layout = new QVBoxLayout( this ); - layout->setMargin( 0 ); - layout->addWidget( d->label ); - d->update(); - connect( d->label, SIGNAL( linkActivated( const QString& ) ), this, SLOT( _k_slotEnableEditing() ) ); -} - - -CommentWidget::~CommentWidget() -{ - delete d; -} - - -void CommentWidget::setComment( const QString& comment ) -{ - d->comment = comment; - d->update(); -} - - -QString CommentWidget::comment() const -{ - return d->comment; -} - - -bool CommentWidget::eventFilter( QObject* watched, QEvent* event ) -{ - return QWidget::eventFilter( watched, event ); -} - -#include "commentwidget.moc" diff --git a/src/commentwidget.h b/src/commentwidget.h deleted file mode 100644 index 8c588518c..000000000 --- a/src/commentwidget.h +++ /dev/null @@ -1,48 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Sebastian Trueg * - * * - * 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 of the License, 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. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#ifndef _NEPOMUK_COMMENT_WIDGET_H_ -#define _NEPOMUK_COMMENT_WIDGET_H_ - -#include - -class CommentWidget : public QWidget -{ - Q_OBJECT - -public: - CommentWidget( QWidget* parent = 0 ); - ~CommentWidget(); - - void setComment( const QString& comment ); - QString comment() const; - -Q_SIGNALS: - void commentChanged( const QString& ); - -private: - bool eventFilter( QObject* watched, QEvent* event ); - - class Private; - Private* const d; - - Q_PRIVATE_SLOT( d, void _k_slotEnableEditing() ) -}; - -#endif diff --git a/src/detailsviewsettingspage.cpp b/src/detailsviewsettingspage.cpp deleted file mode 100644 index 4a439ab1d..000000000 --- a/src/detailsviewsettingspage.cpp +++ /dev/null @@ -1,147 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2006 by Peter Penz * - * * - * 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 of the License, 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. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#include "detailsviewsettingspage.h" - -#include "iconsizegroupbox.h" -#include "dolphinsettings.h" -#include "dolphin_detailsmodesettings.h" -#include "zoomlevelinfo.h" - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -DetailsViewSettingsPage::DetailsViewSettingsPage(QWidget* parent) : - ViewSettingsPageBase(parent), - m_iconSizeGroupBox(0), - m_fontRequester(0), - m_expandableFolders(0) -{ - const int spacing = KDialog::spacingHint(); - const int margin = KDialog::marginHint(); - const QSizePolicy sizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); - - setSpacing(spacing); - setMargin(margin); - - // Create "Icon" properties - m_iconSizeGroupBox = new IconSizeGroupBox(this); - m_iconSizeGroupBox->setSizePolicy(sizePolicy); - - const int min = ZoomLevelInfo::minimumLevel(); - const int max = ZoomLevelInfo::maximumLevel(); - m_iconSizeGroupBox->setDefaultSizeRange(min, max); - m_iconSizeGroupBox->setPreviewSizeRange(min, max); - - connect(m_iconSizeGroupBox, SIGNAL(defaultSizeChanged(int)), - this, SIGNAL(changed())); - connect(m_iconSizeGroupBox, SIGNAL(previewSizeChanged(int)), - this, SIGNAL(changed())); - - // create "Text" properties - QWidget* textGroup = new QGroupBox(i18nc("@title:group", "Text"), this); - textGroup->setSizePolicy(sizePolicy); - - QLabel* fontLabel = new QLabel(i18nc("@label:listbox", "Font:"), textGroup); - m_fontRequester = new DolphinFontRequester(textGroup); - connect(m_fontRequester, SIGNAL(changed()), this, SIGNAL(changed())); - - QHBoxLayout* textLayout = new QHBoxLayout(textGroup); - textLayout->addWidget(fontLabel, 0, Qt::AlignRight); - textLayout->addWidget(m_fontRequester); - - // create "Expandable Folders" checkbox - m_expandableFolders = new QCheckBox(i18nc("@option:check", "Expandable folders"), this); - connect(m_expandableFolders, SIGNAL(toggled(bool)), this, SIGNAL(changed())); - - // Add a dummy widget with no restriction regarding - // a vertical resizing. This assures that the dialog layout - // is not stretched vertically. - new QWidget(this); - - loadSettings(); -} - -DetailsViewSettingsPage::~DetailsViewSettingsPage() -{ -} - -void DetailsViewSettingsPage::applySettings() -{ - DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings(); - - const int iconSize = ZoomLevelInfo::iconSizeForZoomLevel(m_iconSizeGroupBox->defaultSizeValue()); - const int previewSize = ZoomLevelInfo::iconSizeForZoomLevel(m_iconSizeGroupBox->previewSizeValue()); - settings->setIconSize(iconSize); - settings->setPreviewSize(previewSize); - - const QFont font = m_fontRequester->font(); - settings->setUseSystemFont(m_fontRequester->mode() == DolphinFontRequester::SystemFont); - settings->setFontFamily(font.family()); - settings->setFontSize(font.pointSize()); - settings->setItalicFont(font.italic()); - settings->setFontWeight(font.weight()); - - settings->setExpandableFolders(m_expandableFolders->isChecked()); -} - -void DetailsViewSettingsPage::restoreDefaults() -{ - DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings(); - settings->setDefaults(); - loadSettings(); -} - -void DetailsViewSettingsPage::loadSettings() -{ - DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings(); - - const QSize iconSize(settings->iconSize(), settings->iconSize()); - const int iconSizeValue = ZoomLevelInfo::zoomLevelForIconSize(iconSize); - m_iconSizeGroupBox->setDefaultSizeValue(iconSizeValue); - - const QSize previewSize(settings->previewSize(), settings->previewSize()); - const int previewSizeValue = ZoomLevelInfo::zoomLevelForIconSize(previewSize); - m_iconSizeGroupBox->setPreviewSizeValue(previewSizeValue); - - if (settings->useSystemFont()) { - m_fontRequester->setMode(DolphinFontRequester::SystemFont); - } else { - QFont font(settings->fontFamily(), - settings->fontSize()); - font.setItalic(settings->italicFont()); - font.setWeight(settings->fontWeight()); - m_fontRequester->setMode(DolphinFontRequester::CustomFont); - m_fontRequester->setCustomFont(font); - } - - m_expandableFolders->setChecked(settings->expandableFolders()); -} - -#include "detailsviewsettingspage.moc" diff --git a/src/detailsviewsettingspage.h b/src/detailsviewsettingspage.h deleted file mode 100644 index 587d42244..000000000 --- a/src/detailsviewsettingspage.h +++ /dev/null @@ -1,60 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2006 by Peter Penz * - * * - * 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 of the License, 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. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#ifndef DETAILSVIEWSETTINGSPAGE_H -#define DETAILSVIEWSETTINGSPAGE_H - -#include - -class DolphinFontRequester; -class IconSizeGroupBox; -class QCheckBox; - -/** - * @brief Represents the page from the Dolphin Settings which allows - * to modify the settings for the details view. - */ -class DetailsViewSettingsPage : public ViewSettingsPageBase -{ - Q_OBJECT - -public: - DetailsViewSettingsPage(QWidget* parent); - virtual ~DetailsViewSettingsPage(); - - /** - * Applies the settings for the details view. - * The settings are persisted automatically when - * closing Dolphin. - */ - virtual void applySettings(); - - /** Restores the settings to default values. */ - virtual void restoreDefaults(); - -private: - void loadSettings(); - -private: - IconSizeGroupBox* m_iconSizeGroupBox; - DolphinFontRequester* m_fontRequester; - QCheckBox* m_expandableFolders; -}; - -#endif diff --git a/src/dolphin_columnmodesettings.kcfg b/src/dolphin_columnmodesettings.kcfg deleted file mode 100644 index 4fd5ecc6e..000000000 --- a/src/dolphin_columnmodesettings.kcfg +++ /dev/null @@ -1,41 +0,0 @@ - - - - - kiconloader.h - kglobalsettings.h - - - - KGlobalSettings::generalFont().family() - - - - true - - - - KGlobalSettings::generalFont().pointSize() - - - - false - - - - 0 - - - - KIconLoader::SizeSmall - - - - KIconLoader::SizeLarge - - - - 250 - - - diff --git a/src/dolphin_columnmodesettings.kcfgc b/src/dolphin_columnmodesettings.kcfgc deleted file mode 100644 index 55134335a..000000000 --- a/src/dolphin_columnmodesettings.kcfgc +++ /dev/null @@ -1,4 +0,0 @@ -File=dolphin_columnmodesettings.kcfg -ClassName=ColumnModeSettings -Singleton=false -Mutators=true diff --git a/src/dolphin_detailsmodesettings.kcfg b/src/dolphin_detailsmodesettings.kcfg deleted file mode 100644 index 780d70540..000000000 --- a/src/dolphin_detailsmodesettings.kcfg +++ /dev/null @@ -1,41 +0,0 @@ - - - - - kiconloader.h - kglobalsettings.h - - - - KGlobalSettings::generalFont().family() - - - - true - - - - KGlobalSettings::generalFont().pointSize() - - - - false - - - - 0 - - - - KIconLoader::SizeSmall - - - - KIconLoader::SizeLarge - - - - false - - - diff --git a/src/dolphin_detailsmodesettings.kcfgc b/src/dolphin_detailsmodesettings.kcfgc deleted file mode 100644 index 06da2e9e0..000000000 --- a/src/dolphin_detailsmodesettings.kcfgc +++ /dev/null @@ -1,4 +0,0 @@ -File=dolphin_detailsmodesettings.kcfg -ClassName=DetailsModeSettings -Singleton=false -Mutators=true diff --git a/src/dolphin_directoryviewpropertysettings.kcfg b/src/dolphin_directoryviewpropertysettings.kcfg deleted file mode 100644 index ead1325de..000000000 --- a/src/dolphin_directoryviewpropertysettings.kcfg +++ /dev/null @@ -1,65 +0,0 @@ - - - kfileitemdelegate.h - - - - - - When this option is enabled hidden files, such as those starting with a '.', will be shown in the file view. - false - - - - - - - This option controls the style of the view. Currently supported values include icons (0), details (1) and column (2) views. - DolphinView::IconsView - 0 - DolphinView::MaxModeEnum - - - - - When this option is enabled, a preview of the file content is shown as an icon. - false - - - - - When this option is enabled, the sorted items are summarized by their category. - false - - - - - This option defines which attribute (name, size, date, etc.) sorting is performed on. - DolphinView::SortByName - 0 - DolphinView::MaxSortEnum - - - - - Qt::AscendingOrder - Qt::AscendingOrder - Qt::DescendingOrder - - - - - 0 - - - - - The last time these properties were changed by the user. - - - - - diff --git a/src/dolphin_directoryviewpropertysettings.kcfgc b/src/dolphin_directoryviewpropertysettings.kcfgc deleted file mode 100644 index 753642f8c..000000000 --- a/src/dolphin_directoryviewpropertysettings.kcfgc +++ /dev/null @@ -1,6 +0,0 @@ -File=dolphin_directoryviewpropertysettings.kcfg -Singleton=false -ClassName=ViewPropertySettings -Mutators=true -GlobalEnums=true -IncludeFiles=dolphinview.h,qnamespace.h diff --git a/src/dolphin_folderspanelsettings.kcfg b/src/dolphin_folderspanelsettings.kcfg deleted file mode 100644 index 816d783c8..000000000 --- a/src/dolphin_folderspanelsettings.kcfg +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - false - - - diff --git a/src/dolphin_folderspanelsettings.kcfgc b/src/dolphin_folderspanelsettings.kcfgc deleted file mode 100644 index f73e8807d..000000000 --- a/src/dolphin_folderspanelsettings.kcfgc +++ /dev/null @@ -1,4 +0,0 @@ -File=dolphin_folderspanelsettings.kcfg -ClassName=FoldersPanelSettings -Singleton=true -Mutators=true diff --git a/src/dolphin_generalsettings.kcfg b/src/dolphin_generalsettings.kcfg deleted file mode 100644 index 2f4defa92..000000000 --- a/src/dolphin_generalsettings.kcfg +++ /dev/null @@ -1,71 +0,0 @@ - - - - - QDir - - - - false - - - - false - - - - true - - - - QDir::homePath() - - - - false - - - - false - - - - false - - - - false - - - - false - - - - true - - - - false - - - - false - - - - - - - false - - - - true - - - - false - - - diff --git a/src/dolphin_generalsettings.kcfgc b/src/dolphin_generalsettings.kcfgc deleted file mode 100644 index 91b1fee46..000000000 --- a/src/dolphin_generalsettings.kcfgc +++ /dev/null @@ -1,4 +0,0 @@ -File=dolphin_generalsettings.kcfg -ClassName=GeneralSettings -Singleton=false -Mutators=true diff --git a/src/dolphin_iconsmodesettings.kcfg b/src/dolphin_iconsmodesettings.kcfg deleted file mode 100644 index 1311f6d20..000000000 --- a/src/dolphin_iconsmodesettings.kcfg +++ /dev/null @@ -1,67 +0,0 @@ - - - - - kglobalsettings.h - kiconloader.h - QListView - - - - QListView::TopToBottom - - - - true - - - - KGlobalSettings::generalFont().family() - - - - KGlobalSettings::generalFont().pointSize() - - - - false - - - - 0 - - - - - KIconLoader::SizeMedium + QFontMetrics(KGlobalSettings::generalFont()).height() * 2 + 10 - - - - - 96 - - - - 8 - - - - KIconLoader::SizeMedium - - - - - 2 - - - - KIconLoader::SizeHuge - - - diff --git a/src/dolphin_iconsmodesettings.kcfgc b/src/dolphin_iconsmodesettings.kcfgc deleted file mode 100644 index 9987ce938..000000000 --- a/src/dolphin_iconsmodesettings.kcfgc +++ /dev/null @@ -1,4 +0,0 @@ -File=dolphin_iconsmodesettings.kcfg -ClassName=IconsModeSettings -Singleton=false -Mutators=true diff --git a/src/dolphincolumnview.cpp b/src/dolphincolumnview.cpp index 05c33d7dd..bc488b8ae 100644 --- a/src/dolphincolumnview.cpp +++ b/src/dolphincolumnview.cpp @@ -21,7 +21,7 @@ #include "dolphincolumnwidget.h" #include "dolphincontroller.h" -#include "dolphinsettings.h" +#include "settings/dolphinsettings.h" #include "zoomlevelinfo.h" #include "dolphin_columnmodesettings.h" diff --git a/src/dolphincolumnwidget.cpp b/src/dolphincolumnwidget.cpp index d7d8bb500..b86cd7269 100644 --- a/src/dolphincolumnwidget.cpp +++ b/src/dolphincolumnwidget.cpp @@ -24,14 +24,14 @@ #include "dolphincontroller.h" #include "dolphindirlister.h" #include "dolphinsortfilterproxymodel.h" -#include "dolphinsettings.h" +#include "settings/dolphinsettings.h" #include "dolphinviewautoscroller.h" #include "dolphin_columnmodesettings.h" #include "dolphin_generalsettings.h" #include "draganddrophelper.h" #include "folderexpander.h" #include "selectionmanager.h" -#include "tooltipmanager.h" +#include "tooltips/tooltipmanager.h" #include #include diff --git a/src/dolphincontextmenu.cpp b/src/dolphincontextmenu.cpp index 99735ea9e..a7f7df36c 100644 --- a/src/dolphincontextmenu.cpp +++ b/src/dolphincontextmenu.cpp @@ -22,7 +22,7 @@ #include "dolphinmainwindow.h" #include "dolphinnewmenu.h" -#include "dolphinsettings.h" +#include "settings/dolphinsettings.h" #include "dolphinview.h" #include "dolphinviewcontainer.h" #include "dolphin_generalsettings.h" diff --git a/src/dolphindetailsview.cpp b/src/dolphindetailsview.cpp index 2d18c8e18..acfff6a65 100644 --- a/src/dolphindetailsview.cpp +++ b/src/dolphindetailsview.cpp @@ -23,7 +23,7 @@ #include "dolphinmodel.h" #include "dolphincontroller.h" #include "dolphinfileitemdelegate.h" -#include "dolphinsettings.h" +#include "settings/dolphinsettings.h" #include "dolphinsortfilterproxymodel.h" #include "dolphinviewautoscroller.h" #include "draganddrophelper.h" diff --git a/src/dolphinfileplacesview.cpp b/src/dolphinfileplacesview.cpp deleted file mode 100644 index df3e6fd87..000000000 --- a/src/dolphinfileplacesview.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Peter Penz * - * * - * 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 of the License, 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. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#include "dolphinfileplacesview.h" -#include "draganddrophelper.h" -#include -#include - -DolphinFilePlacesView::DolphinFilePlacesView(QWidget* parent) : - KFilePlacesView(parent), - m_mouseButtons(Qt::NoButton) -{ - setDropOnPlaceEnabled(true); - connect(this, SIGNAL(urlsDropped(const KUrl&, QDropEvent*, QWidget*)), - this, SLOT(slotUrlsDropped(const KUrl&, QDropEvent*, QWidget*))); - connect(this, SIGNAL(urlChanged(const KUrl&)), - this, SLOT(emitExtendedUrlChangedSignal(const KUrl&))); -} - -DolphinFilePlacesView::~DolphinFilePlacesView() -{ -} - -void DolphinFilePlacesView::mousePressEvent(QMouseEvent* event) -{ - m_mouseButtons = event->buttons(); - KFilePlacesView::mousePressEvent(event); -} - -void DolphinFilePlacesView::slotUrlsDropped(const KUrl& dest, QDropEvent* event, QWidget* parent) -{ - DragAndDropHelper::instance().dropUrls(KFileItem(), dest, event, parent); -} - -void DolphinFilePlacesView::emitExtendedUrlChangedSignal(const KUrl& url) -{ - emit urlChanged(url, m_mouseButtons); -} - -#include "dolphinfileplacesview.moc" diff --git a/src/dolphinfileplacesview.h b/src/dolphinfileplacesview.h deleted file mode 100644 index 46d574606..000000000 --- a/src/dolphinfileplacesview.h +++ /dev/null @@ -1,51 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Peter Penz * - * * - * 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 of the License, 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. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#ifndef DOLPHINFILEPLACESVIEW_H -#define DOLPHINFILEPLACESVIEW_H - -#include - -/** - * @brief Combines bookmarks and mounted devices as list which is - * embedded as panel. - */ -class DolphinFilePlacesView : public KFilePlacesView -{ - Q_OBJECT - -public: - DolphinFilePlacesView(QWidget* parent); - virtual ~DolphinFilePlacesView(); - -signals: - void urlChanged(const KUrl& url, Qt::MouseButtons buttons); - -protected: - virtual void mousePressEvent(QMouseEvent* event); - -private slots: - void slotUrlsDropped(const KUrl& dest, QDropEvent* event, QWidget* parent); - void emitExtendedUrlChangedSignal(const KUrl& url); - -private: - Qt::MouseButtons m_mouseButtons; -}; - -#endif // DOLPHINFILEPLACESVIEW_H diff --git a/src/dolphinfontrequester.cpp b/src/dolphinfontrequester.cpp deleted file mode 100644 index 2fc444029..000000000 --- a/src/dolphinfontrequester.cpp +++ /dev/null @@ -1,111 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Peter Penz * - * * - * 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 of the License, 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. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#include "dolphinfontrequester.h" - -#include -#include -#include -#include - -#include -#include - -DolphinFontRequester::DolphinFontRequester(QWidget* parent) : - KHBox(parent), - m_modeCombo(0), - m_chooseFontButton(0), - m_mode(SystemFont), - m_customFont() -{ - setSpacing(KDialog::spacingHint()); - - m_modeCombo = new KComboBox(this); - m_modeCombo->addItem(i18nc("@item:inlistbox Font", "System Font")); - m_modeCombo->addItem(i18nc("@item:inlistbox Font", "Custom Font")); - connect(m_modeCombo, SIGNAL(activated(int)), - this, SLOT(changeMode(int))); - - m_chooseFontButton = new QPushButton(i18nc("@action:button Choose font", "Choose..."), this); - connect(m_chooseFontButton, SIGNAL(clicked()), - this, SLOT(openFontDialog())); - - changeMode(m_modeCombo->currentIndex()); -} - -DolphinFontRequester::~DolphinFontRequester() -{ -} - -void DolphinFontRequester::setMode(Mode mode) -{ - m_mode = mode; - m_modeCombo->setCurrentIndex(m_mode); - m_modeCombo->setFont(font()); - m_chooseFontButton->setEnabled(m_mode == CustomFont); -} - -DolphinFontRequester::Mode DolphinFontRequester::mode() const -{ - return m_mode; -} - -QFont DolphinFontRequester::font() const -{ - return (m_mode == CustomFont) ? m_customFont : KGlobalSettings::generalFont(); -} - -void DolphinFontRequester::setCustomFont(const QFont& font) -{ - m_customFont = font; -} - -QFont DolphinFontRequester::customFont() const -{ - return m_customFont; -} - -bool DolphinFontRequester::event(QEvent* event) -{ - if (event->type() == QEvent::Polish) { - m_modeCombo->setFont(font()); - } - return KHBox::event(event); -} - -void DolphinFontRequester::openFontDialog() -{ - QFont font; - const int result = KFontDialog::getFont(font, - KFontChooser::NoDisplayFlags, - this); - if (result == KFontDialog::Accepted) { - m_customFont = font; - m_modeCombo->setFont(m_customFont); - emit changed(); - } -} - -void DolphinFontRequester::changeMode(int index) -{ - setMode((index == CustomFont) ? CustomFont : SystemFont); - emit changed(); -} - -#include "dolphinfontrequester.moc" diff --git a/src/dolphinfontrequester.h b/src/dolphinfontrequester.h deleted file mode 100644 index 03a062b2e..000000000 --- a/src/dolphinfontrequester.h +++ /dev/null @@ -1,79 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Peter Penz * - * * - * 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 of the License, 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. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#ifndef DOLPHINFONTREQUESTER_H -#define DOLPHINFONTREQUESTER_H - -#include - -#include - -class KComboBox; -class QPushButton; - -/** - * @brief Allows to select between using the system font or a custom font. - */ -class DolphinFontRequester : public KHBox -{ - Q_OBJECT - -public: - enum Mode - { - SystemFont = 0, - CustomFont = 1 - }; - - DolphinFontRequester(QWidget* parent); - virtual ~DolphinFontRequester(); - - void setMode(Mode mode); - Mode mode() const; - - /** - * Returns the custom font (see DolphinFontRequester::customFont()), - * if the mode is \a CustomFont, otherwise the system font is - * returned. - */ - QFont font() const; - - void setCustomFont(const QFont& font); - QFont customFont() const; - -signals: - /** Is emitted, if the font has been changed. */ - void changed(); - -protected: - bool event(QEvent* event); - -private slots: - void openFontDialog(); - void changeMode(int index); - -private: - KComboBox* m_modeCombo; - QPushButton* m_chooseFontButton; - - Mode m_mode; - QFont m_customFont; -}; - -#endif diff --git a/src/dolphiniconsview.cpp b/src/dolphiniconsview.cpp index f32ecbd3d..885a49101 100644 --- a/src/dolphiniconsview.cpp +++ b/src/dolphiniconsview.cpp @@ -21,7 +21,7 @@ #include "dolphincategorydrawer.h" #include "dolphincontroller.h" -#include "dolphinsettings.h" +#include "settings/dolphinsettings.h" #include "dolphinviewautoscroller.h" #include "dolphin_iconsmodesettings.h" #include "dolphin_generalsettings.h" diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index 9c55a40f4..c4d263bfd 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -25,20 +25,20 @@ #include #include "dolphinapplication.h" -#include "dolphinfileplacesview.h" +#include "panels/places/dolphinfileplacesview.h" #include "dolphinnewmenu.h" -#include "dolphinsettings.h" -#include "dolphinsettingsdialog.h" +#include "settings/dolphinsettings.h" +#include "settings/dolphinsettingsdialog.h" #include "dolphinstatusbar.h" #include "dolphinviewcontainer.h" -#include "infosidebarpage.h" -#include "metadatawidget.h" +#include "panels/information/infosidebarpage.h" +#include "panels/information/metadatawidget.h" #include "mainwindowadaptor.h" -#include "treeviewsidebarpage.h" +#include "panels/folders/treeviewsidebarpage.h" #include "viewproperties.h" #ifndef Q_OS_WIN -#include "terminalsidebarpage.h" +#include "panels/terminal/terminalsidebarpage.h" #endif #include "dolphin_generalsettings.h" diff --git a/src/dolphinmainwindow.h b/src/dolphinmainwindow.h index 4220e825f..b1e1ea5d0 100644 --- a/src/dolphinmainwindow.h +++ b/src/dolphinmainwindow.h @@ -23,7 +23,7 @@ #define DOLPHIN_MAINWINDOW_H #include "dolphinview.h" -#include "sidebarpage.h" +#include "panels/sidebarpage.h" #include diff --git a/src/dolphinsettings.cpp b/src/dolphinsettings.cpp deleted file mode 100644 index 5b91001ef..000000000 --- a/src/dolphinsettings.cpp +++ /dev/null @@ -1,78 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2006 by Peter Penz (peter.penz@gmx.at), * - * Cvetoslav Ludmiloff and Patrice Tremblay * - * * - * 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 of the License, 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. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#include "dolphinsettings.h" - -#include -#include -#include -#include - -#include "dolphin_columnmodesettings.h" -#include "dolphin_detailsmodesettings.h" -#include "dolphin_generalsettings.h" -#include "dolphin_iconsmodesettings.h" - -class DolphinSettingsSingleton -{ -public: - DolphinSettings instance; -}; -K_GLOBAL_STATIC(DolphinSettingsSingleton, s_settings) - -DolphinSettings& DolphinSettings::instance() -{ - return s_settings->instance; -} - -void DolphinSettings::save() -{ - m_generalSettings->writeConfig(); - m_iconsModeSettings->writeConfig(); - m_detailsModeSettings->writeConfig(); - m_columnModeSettings->writeConfig(); -} - -DolphinSettings::DolphinSettings() -{ - m_generalSettings = new GeneralSettings(); - m_iconsModeSettings = new IconsModeSettings(); - m_detailsModeSettings = new DetailsModeSettings(); - m_columnModeSettings = new ColumnModeSettings(); - m_placesModel = new KFilePlacesModel(); -} - -DolphinSettings::~DolphinSettings() -{ - delete m_generalSettings; - m_generalSettings = 0; - - delete m_iconsModeSettings; - m_iconsModeSettings = 0; - - delete m_detailsModeSettings; - m_detailsModeSettings = 0; - - delete m_columnModeSettings; - m_columnModeSettings = 0; - - delete m_placesModel; - m_placesModel = 0; -} diff --git a/src/dolphinsettings.h b/src/dolphinsettings.h deleted file mode 100644 index 55fa327ef..000000000 --- a/src/dolphinsettings.h +++ /dev/null @@ -1,92 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2006 by Peter Penz * - * peter.penz@gmx.at * - * * - * 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 of the License, 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. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#ifndef DOLPHINSETTINGS_H -#define DOLPHINSETTINGS_H - -#include - -class ColumnModeSettings; -class DetailsModeSettings; -class GeneralSettings; -class IconsModeSettings; -class KFilePlacesModel; - -/** - * @brief Manages and stores all settings from Dolphin. - * - * The following properties are stored: - * - home URL - * - default view mode - * - URL navigator state (editable or not) - * - split view - * - properties for views - */ -class LIBDOLPHINPRIVATE_EXPORT DolphinSettings -{ -public: - static DolphinSettings& instance(); - - GeneralSettings* generalSettings() const; - IconsModeSettings* iconsModeSettings() const; - DetailsModeSettings* detailsModeSettings() const; - ColumnModeSettings* columnModeSettings() const; - KFilePlacesModel* placesModel() const; - virtual void save(); - -protected: - DolphinSettings(); - virtual ~DolphinSettings(); - friend class DolphinSettingsSingleton; - -private: - GeneralSettings* m_generalSettings; - IconsModeSettings* m_iconsModeSettings; - DetailsModeSettings* m_detailsModeSettings; - ColumnModeSettings* m_columnModeSettings; - KFilePlacesModel* m_placesModel; -}; - -inline GeneralSettings* DolphinSettings::generalSettings() const -{ - return m_generalSettings; -} - -inline IconsModeSettings* DolphinSettings::iconsModeSettings() const -{ - return m_iconsModeSettings; -} - -inline DetailsModeSettings* DolphinSettings::detailsModeSettings() const -{ - return m_detailsModeSettings; -} - -inline ColumnModeSettings* DolphinSettings::columnModeSettings() const -{ - return m_columnModeSettings; -} - -inline KFilePlacesModel* DolphinSettings::placesModel() const -{ - return m_placesModel; -} - -#endif diff --git a/src/dolphinsettingsdialog.cpp b/src/dolphinsettingsdialog.cpp deleted file mode 100644 index 7b1e23266..000000000 --- a/src/dolphinsettingsdialog.cpp +++ /dev/null @@ -1,114 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2006 by Peter Penz * - * peter.penz@gmx.at * - * * - * 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 of the License, 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. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#include "dolphinsettingsdialog.h" - -#include "dolphinapplication.h" -#include "dolphinmainwindow.h" -#include "generalsettingspage.h" -#include "startupsettingspage.h" -#include "viewsettingspage.h" - -#include -#include -#include - -DolphinSettingsDialog::DolphinSettingsDialog(DolphinMainWindow* mainWindow) : - KPageDialog(mainWindow), - m_pages() - -{ - const QSize minSize = minimumSize(); - setMinimumSize(QSize(512, minSize.height())); - - setFaceType(List); - setCaption(i18nc("@title:window", "Dolphin Preferences")); - setButtons(Ok | Apply | Cancel | Default); - enableButtonApply(false); - setDefaultButton(Ok); - - StartupSettingsPage* startupSettingsPage = new StartupSettingsPage(mainWindow, this); - KPageWidgetItem* startupSettingsFrame = addPage(startupSettingsPage, - i18nc("@title:group", "Startup")); - startupSettingsFrame->setIcon(KIcon("go-home")); - connect(startupSettingsPage, SIGNAL(changed()), this, SLOT(enableApply())); - - ViewSettingsPage* viewSettingsPage = new ViewSettingsPage(mainWindow, this); - KPageWidgetItem* viewSettingsFrame = addPage(viewSettingsPage, - i18nc("@title:group", "View Modes")); - viewSettingsFrame->setIcon(KIcon("view-choose")); - connect(viewSettingsPage, SIGNAL(changed()), this, SLOT(enableApply())); - - GeneralSettingsPage* generalSettingsPage = new GeneralSettingsPage(mainWindow, this); - KPageWidgetItem* generalSettingsFrame = addPage(generalSettingsPage, - i18nc("@title:group General settings", "General")); - generalSettingsFrame->setIcon(KIcon("system-run")); - connect(generalSettingsPage, SIGNAL(changed()), this, SLOT(enableApply())); - - const KConfigGroup dialogConfig(KSharedConfig::openConfig("dolphinrc"), "SettingsDialog"); - restoreDialogSize(dialogConfig); - - m_pages.append(startupSettingsPage); - m_pages.append(viewSettingsPage); - m_pages.append(generalSettingsPage); -} - -DolphinSettingsDialog::~DolphinSettingsDialog() -{ - KConfigGroup dialogConfig(KSharedConfig::openConfig("dolphinrc"), "SettingsDialog"); - saveDialogSize(dialogConfig); -} - -void DolphinSettingsDialog::slotButtonClicked(int button) -{ - if ((button == Ok) || (button == Apply)) { - applySettings(); - } else if (button == Default) { - const QString text(i18nc("@info", "All settings will be reset to default values. Do you want to continue?")); - if (KMessageBox::questionYesNo(this, text) == KMessageBox::Yes) { - restoreDefaults(); - } - } - - KPageDialog::slotButtonClicked(button); -} - -void DolphinSettingsDialog::enableApply() -{ - enableButtonApply(true); -} - -void DolphinSettingsDialog::applySettings() -{ - foreach (SettingsPageBase* page, m_pages) { - page->applySettings(); - } - DolphinApplication::app()->refreshMainWindows(); -} - -void DolphinSettingsDialog::restoreDefaults() -{ - foreach (SettingsPageBase* page, m_pages) { - page->restoreDefaults(); - } - DolphinApplication::app()->refreshMainWindows(); -} - -#include "dolphinsettingsdialog.moc" diff --git a/src/dolphinsettingsdialog.h b/src/dolphinsettingsdialog.h deleted file mode 100644 index fc17b3774..000000000 --- a/src/dolphinsettingsdialog.h +++ /dev/null @@ -1,60 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2006 by Peter Penz * - * peter.penz@gmx.at * - * * - * 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 of the License, 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. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#ifndef DOLPHINSETTINGSDIALOG_H -#define DOLPHINSETTINGSDIALOG_H - -#include - -class DolphinMainWindow; -class SettingsPageBase; - -/** - * @brief Settings dialog for Dolphin. - * - * Contains the pages for startup settings, general settings and view settings. - * - * @author Peter Penz - */ -class DolphinSettingsDialog : public KPageDialog -{ - Q_OBJECT - -public: - explicit DolphinSettingsDialog(DolphinMainWindow* mainWindow); - virtual ~DolphinSettingsDialog(); - -protected slots: - /** @see KDialog::slotButtonClicked() */ - virtual void slotButtonClicked(int button); - -private slots: - /** Enables the Apply button. */ - void enableApply(); - -private: - void applySettings(); - void restoreDefaults(); - -private: - QList m_pages; -}; - -#endif diff --git a/src/dolphinstatusbar.cpp b/src/dolphinstatusbar.cpp index caa784049..7a9b5dc8a 100644 --- a/src/dolphinstatusbar.cpp +++ b/src/dolphinstatusbar.cpp @@ -19,7 +19,7 @@ ***************************************************************************/ #include "dolphinstatusbar.h" -#include "dolphinsettings.h" +#include "settings/dolphinsettings.h" #include "dolphinview.h" #include "dolphin_generalsettings.h" #include "statusbarmessagelabel.h" diff --git a/src/dolphintooltip.cpp b/src/dolphintooltip.cpp deleted file mode 100644 index bc3be33aa..000000000 --- a/src/dolphintooltip.cpp +++ /dev/null @@ -1,50 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Simon St James * - * * - * 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 of the License, 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. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#include "dolphintooltip.h" - -#include -#include -#include - -#include - -DolphinBalloonTooltipDelegate::DolphinBalloonTooltipDelegate() -{ -} - -DolphinBalloonTooltipDelegate::~DolphinBalloonTooltipDelegate() -{ -} - -// Delegate everything to the base class, after re-setting the decorationSize -// to the preview size. -QSize DolphinBalloonTooltipDelegate::sizeHint(const KStyleOptionToolTip* option, const KToolTipItem* item) const -{ - KStyleOptionToolTip updatedStyleOption = *option; - updatedStyleOption.decorationSize = QSize(PREVIEW_WIDTH, PREVIEW_HEIGHT); - return KFormattedBalloonTipDelegate::sizeHint(&updatedStyleOption, item); -} - -void DolphinBalloonTooltipDelegate::paint(QPainter* painter, const KStyleOptionToolTip* option, const KToolTipItem* item) const -{ - KStyleOptionToolTip updatedStyleOption = *option; - updatedStyleOption.decorationSize = QSize(PREVIEW_WIDTH, PREVIEW_HEIGHT); - return KFormattedBalloonTipDelegate::paint(painter, &updatedStyleOption, item); -} diff --git a/src/dolphintooltip.h b/src/dolphintooltip.h deleted file mode 100644 index cfc438831..000000000 --- a/src/dolphintooltip.h +++ /dev/null @@ -1,47 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Simon St James * - * * - * 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 of the License, 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. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -// NOTE: proper documentation will be added once the code is better developed. - -#ifndef DOLPHINTOOLTIP_H -#define DOLPHINTOOLTIP_H - -#include "ktooltip.h" -#include "kformattedballoontipdelegate.h" - -#include -#include - -class KFileItem; -class QPixmap; - -const int PREVIEW_WIDTH = 256; -const int PREVIEW_HEIGHT = 256; - - -class DolphinBalloonTooltipDelegate : public KFormattedBalloonTipDelegate -{ -public: - DolphinBalloonTooltipDelegate(); - virtual ~DolphinBalloonTooltipDelegate(); - - virtual QSize sizeHint(const KStyleOptionToolTip* option, const KToolTipItem* item) const; - virtual void paint(QPainter* painter, const KStyleOptionToolTip* option, const KToolTipItem* item) const; -}; -#endif diff --git a/src/dolphinview.cpp b/src/dolphinview.cpp index 0bd24ecb3..6681fe189 100644 --- a/src/dolphinview.cpp +++ b/src/dolphinview.cpp @@ -57,12 +57,12 @@ #include "dolphindetailsview.h" #include "dolphin_detailsmodesettings.h" #include "dolphiniconsview.h" -#include "dolphinsettings.h" +#include "settings/dolphinsettings.h" #include "dolphin_generalsettings.h" #include "draganddrophelper.h" #include "folderexpander.h" #include "renamedialog.h" -#include "tooltipmanager.h" +#include "tooltips/tooltipmanager.h" #include "viewproperties.h" #include "zoomlevelinfo.h" diff --git a/src/dolphinviewactionhandler.cpp b/src/dolphinviewactionhandler.cpp index d563b3dd2..45603c286 100644 --- a/src/dolphinviewactionhandler.cpp +++ b/src/dolphinviewactionhandler.cpp @@ -19,7 +19,7 @@ #include "dolphinviewactionhandler.h" -#include "viewpropertiesdialog.h" +#include "settings/viewpropertiesdialog.h" #include "dolphinview.h" #include "zoomlevelinfo.h" diff --git a/src/dolphinviewcontainer.cpp b/src/dolphinviewcontainer.cpp index 3cd6b34f2..f09d3d1c9 100644 --- a/src/dolphinviewcontainer.cpp +++ b/src/dolphinviewcontainer.cpp @@ -58,7 +58,7 @@ #include "filterbar.h" #include "kurlnavigator.h" #include "viewproperties.h" -#include "dolphinsettings.h" +#include "settings/dolphinsettings.h" #include "dolphin_generalsettings.h" DolphinViewContainer::DolphinViewContainer(DolphinMainWindow* mainWindow, diff --git a/src/folderexpander.cpp b/src/folderexpander.cpp index 50f2bcf91..091cd0c2c 100644 --- a/src/folderexpander.cpp +++ b/src/folderexpander.cpp @@ -20,7 +20,7 @@ #include "folderexpander.h" #include "dolphinview.h" -#include "dolphinsettings.h" +#include "settings/dolphinsettings.h" #include "dolphin_generalsettings.h" #include diff --git a/src/generalsettingspage.cpp b/src/generalsettingspage.cpp deleted file mode 100644 index 68193b4e4..000000000 --- a/src/generalsettingspage.cpp +++ /dev/null @@ -1,170 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2006 by Peter Penz (peter.penz@gmx.at) and * - * and Patrice Tremblay * - * * - * 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 of the License, 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. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#include "generalsettingspage.h" - -#include "dolphinsettings.h" - -#include "dolphin_generalsettings.h" - -#include -#include -#include - -#include -#include -#include -#include - -GeneralSettingsPage::GeneralSettingsPage(DolphinMainWindow* mainWin, QWidget* parent) : - SettingsPageBase(parent), - m_confirmMoveToTrash(0), - m_confirmDelete(0), - m_showDeleteCommand(0), - m_showCopyMoveMenu(0), - m_showZoomSlider(0), - m_showSpaceInfo(0), - m_browseThroughArchives(0), - m_renameInline(0), - m_autoExpandFolders(0) -{ - Q_UNUSED(mainWin); - - const int spacing = KDialog::spacingHint(); - - QVBoxLayout* topLayout = new QVBoxLayout(this); - KVBox* vBox = new KVBox(this); - vBox->setSpacing(spacing); - - // create 'Ask Confirmation For' group - QGroupBox* confirmBox = new QGroupBox(i18nc("@title:group", "Ask For Confirmation When"), vBox); - m_confirmMoveToTrash = new QCheckBox(i18nc("@option:check Ask for Confirmation When", - "Moving files or folders to trash"), confirmBox); - connect(m_confirmMoveToTrash, SIGNAL(toggled(bool)), this, SIGNAL(changed())); - m_confirmDelete = new QCheckBox(i18nc("@option:check Ask for Confirmation When", - "Deleting files or folders"), confirmBox); - connect(m_confirmDelete, SIGNAL(toggled(bool)), this, SIGNAL(changed())); - - QVBoxLayout* confirmBoxLayout = new QVBoxLayout(confirmBox); - confirmBoxLayout->addWidget(m_confirmMoveToTrash); - confirmBoxLayout->addWidget(m_confirmDelete); - - QGroupBox* contextMenuBox = new QGroupBox(i18nc("@title:group", "Context Menu"), vBox); - - // create 'Show the command 'Delete' in context menu' checkbox - m_showDeleteCommand = new QCheckBox(i18nc("@option:check", "Show 'Delete' command"), contextMenuBox); - connect(m_showDeleteCommand, SIGNAL(toggled(bool)), this, SIGNAL(changed())); - - m_showCopyMoveMenu = new QCheckBox(i18nc("@option:check", "Show 'Copy To' and 'Move To' commands"), contextMenuBox); - connect(m_showCopyMoveMenu, SIGNAL(toggled(bool)), this, SIGNAL(changed())); - - QVBoxLayout* contextMenuBoxLayout = new QVBoxLayout(contextMenuBox); - contextMenuBoxLayout->addWidget(m_showDeleteCommand); - contextMenuBoxLayout->addWidget(m_showCopyMoveMenu); - - QGroupBox* statusBarBox = new QGroupBox(i18nc("@title:group", "Status Bar"), vBox); - - m_showZoomSlider = new QCheckBox(i18nc("@option:check", "Show zoom slider"), statusBarBox); - connect(m_showZoomSlider, SIGNAL(toggled(bool)), this, SIGNAL(changed())); - - m_showSpaceInfo = new QCheckBox(i18nc("@option:check", "Show space information"), statusBarBox); - connect(m_showSpaceInfo, SIGNAL(toggled(bool)), this, SIGNAL(changed())); - - QVBoxLayout* statusBarBoxLayout = new QVBoxLayout(statusBarBox); - statusBarBoxLayout->addWidget(m_showZoomSlider); - statusBarBoxLayout->addWidget(m_showSpaceInfo); - - m_browseThroughArchives = new QCheckBox(i18nc("@option:check", "Browse through archives"), vBox); - connect(m_browseThroughArchives, SIGNAL(toggled(bool)), this, SIGNAL(changed())); - - m_renameInline = new QCheckBox(i18nc("@option:check", "Rename inline"), vBox); - connect(m_renameInline, SIGNAL(toggled(bool)), this, SIGNAL(changed())); - - m_autoExpandFolders = new QCheckBox(i18nc("option:check", "Open folders during drag operations"), vBox); - connect(m_autoExpandFolders, SIGNAL(toggled(bool)), this, SIGNAL(changed())); - - // Add a dummy widget with no restriction regarding - // a vertical resizing. This assures that the dialog layout - // is not stretched vertically. - new QWidget(vBox); - - topLayout->addWidget(vBox); - - loadSettings(); -} - -GeneralSettingsPage::~GeneralSettingsPage() -{ -} - -void GeneralSettingsPage::applySettings() -{ - GeneralSettings* settings = DolphinSettings::instance().generalSettings(); - - KSharedConfig::Ptr kioConfig = KSharedConfig::openConfig("kiorc", KConfig::NoGlobals); - KConfigGroup confirmationGroup(kioConfig, "Confirmations"); - confirmationGroup.writeEntry("ConfirmTrash", m_confirmMoveToTrash->isChecked()); - confirmationGroup.writeEntry("ConfirmDelete", m_confirmDelete->isChecked()); - confirmationGroup.sync(); - - KSharedConfig::Ptr globalConfig = KSharedConfig::openConfig("kdeglobals", KConfig::NoGlobals); - KConfigGroup configGroup(globalConfig, "KDE"); - configGroup.writeEntry("ShowDeleteCommand", m_showDeleteCommand->isChecked()); - configGroup.sync(); - - settings->setShowCopyMoveMenu(m_showCopyMoveMenu->isChecked()); - settings->setShowZoomSlider(m_showZoomSlider->isChecked()); - settings->setShowSpaceInfo(m_showSpaceInfo->isChecked()); - settings->setBrowseThroughArchives(m_browseThroughArchives->isChecked()); - settings->setRenameInline(m_renameInline->isChecked()); - settings->setAutoExpandFolders(m_autoExpandFolders->isChecked()); -} - -void GeneralSettingsPage::restoreDefaults() -{ - GeneralSettings* settings = DolphinSettings::instance().generalSettings(); - settings->setDefaults(); - - // TODO: reset default settings for trash and show delete command... - - loadSettings(); -} - -void GeneralSettingsPage::loadSettings() -{ - KSharedConfig::Ptr kioConfig = KSharedConfig::openConfig("kiorc", KConfig::IncludeGlobals); - const KConfigGroup confirmationGroup(kioConfig, "Confirmations"); - m_confirmMoveToTrash->setChecked(confirmationGroup.readEntry("ConfirmTrash", false)); - m_confirmDelete->setChecked(confirmationGroup.readEntry("ConfirmDelete", true)); - - KSharedConfig::Ptr globalConfig = KSharedConfig::openConfig("kdeglobals", KConfig::IncludeGlobals); - KConfigGroup configGroup(globalConfig, "KDE"); - m_showDeleteCommand->setChecked(configGroup.readEntry("ShowDeleteCommand", false)); - - GeneralSettings* settings = DolphinSettings::instance().generalSettings(); - m_showCopyMoveMenu->setChecked(settings->showCopyMoveMenu()); - m_showZoomSlider->setChecked(settings->showZoomSlider()); - m_showSpaceInfo->setChecked(settings->showSpaceInfo()); - m_browseThroughArchives->setChecked(settings->browseThroughArchives()); - m_renameInline->setChecked(settings->renameInline()); - m_autoExpandFolders->setChecked(settings->autoExpandFolders()); -} - -#include "generalsettingspage.moc" diff --git a/src/generalsettingspage.h b/src/generalsettingspage.h deleted file mode 100644 index da7e72f0f..000000000 --- a/src/generalsettingspage.h +++ /dev/null @@ -1,64 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2006 by Peter Penz * - * peter.penz@gmx.at * - * * - * 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 of the License, 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. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ -#ifndef GENERALSETTINGSPAGE_H -#define GENERALSETTINGSPAGE_H - -#include - -class DolphinMainWindow; -class QLineEdit; -class QCheckBox; - -/** - * @brief Page for the 'General' settings of the Dolphin settings dialog. - */ -class GeneralSettingsPage : public SettingsPageBase -{ - Q_OBJECT - -public: - GeneralSettingsPage(DolphinMainWindow* mainWindow, QWidget* parent); - virtual ~GeneralSettingsPage(); - - /** @see SettingsPageBase::applySettings() */ - virtual void applySettings(); - - /** @see SettingsPageBase::restoreDefaults() */ - virtual void restoreDefaults(); - -private: - void loadSettings(); - -private: - QCheckBox* m_confirmMoveToTrash; - QCheckBox* m_confirmDelete; - - QCheckBox* m_showDeleteCommand; - QCheckBox* m_showCopyMoveMenu; - - QCheckBox* m_showZoomSlider; - QCheckBox* m_showSpaceInfo; - - QCheckBox* m_browseThroughArchives; - QCheckBox* m_renameInline; - QCheckBox* m_autoExpandFolders; -}; - -#endif diff --git a/src/generalviewsettingspage.cpp b/src/generalviewsettingspage.cpp deleted file mode 100644 index 9ef2ee97e..000000000 --- a/src/generalviewsettingspage.cpp +++ /dev/null @@ -1,201 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2006 by Peter Penz * - * * - * 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 of the License, 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. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#include "generalviewsettingspage.h" -#include "dolphinmainwindow.h" -#include "dolphinsettings.h" -#include "dolphinviewcontainer.h" -#include "viewproperties.h" - -#include "dolphin_generalsettings.h" - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -GeneralViewSettingsPage::GeneralViewSettingsPage(const KUrl& url, - QWidget* parent) : - ViewSettingsPageBase(parent), - m_url(url), - m_localProps(0), - m_globalProps(0), - m_maxPreviewSize(0), - m_spinBox(0), - m_useFileThumbnails(0), - m_showSelectionToggle(0), - m_showToolTips(0) -{ - const int spacing = KDialog::spacingHint(); - const int margin = KDialog::marginHint(); - const QSizePolicy sizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); - - setSpacing(spacing); - setMargin(margin); - - QGroupBox* propsBox = new QGroupBox(i18nc("@title:group", "View Properties"), this); - - m_localProps = new QRadioButton(i18nc("@option:radio", "Remember view properties for each folder"), propsBox); - connect(m_localProps, SIGNAL(toggled(bool)), this, SIGNAL(changed())); - - m_globalProps = new QRadioButton(i18nc("@option:radio", "Use common view properties for all folders"), propsBox); - connect(m_globalProps, SIGNAL(toggled(bool)), this, SIGNAL(changed())); - - QVBoxLayout* propsBoxLayout = new QVBoxLayout(propsBox); - propsBoxLayout->addWidget(m_localProps); - propsBoxLayout->addWidget(m_globalProps); - - // create 'File Previews' box - QGroupBox* previewBox = new QGroupBox(i18nc("@title:group", "File Previews"), this); - - KHBox* vBox = new KHBox(previewBox); - vBox->setSpacing(spacing); - - new QLabel(i18nc("@label:slider", "Maximum file size:"), vBox); - m_maxPreviewSize = new QSlider(Qt::Horizontal, vBox); - - m_spinBox = new QSpinBox(vBox); - - connect(m_maxPreviewSize, SIGNAL(valueChanged(int)), - m_spinBox, SLOT(setValue(int))); - connect(m_spinBox, SIGNAL(valueChanged(int)), - m_maxPreviewSize, SLOT(setValue(int))); - - connect(m_maxPreviewSize, SIGNAL(valueChanged(int)), - this, SIGNAL(changed())); - connect(m_spinBox, SIGNAL(valueChanged(int)), - this, SIGNAL(changed())); - - m_useFileThumbnails = new QCheckBox(i18nc("@option:check", "Use thumbnails embedded in files"), previewBox); - connect(m_useFileThumbnails, SIGNAL(toggled(bool)), this, SIGNAL(changed())); - - QVBoxLayout* previewBoxLayout = new QVBoxLayout(previewBox); - previewBoxLayout->addWidget(vBox); - previewBoxLayout->addWidget(m_useFileThumbnails); - - m_showSelectionToggle = new QCheckBox(i18nc("@option:check", "Show selection marker"), this); - connect(m_showSelectionToggle, SIGNAL(toggled(bool)), this, SIGNAL(changed())); - - m_showToolTips = new QCheckBox(i18nc("@option:check", "Show tooltips"), this); - connect(m_showToolTips, SIGNAL(toggled(bool)), this, SIGNAL(changed())); - - // Add a dummy widget with no restriction regarding - // a vertical resizing. This assures that the dialog layout - // is not stretched vertically. - new QWidget(this); - - loadSettings(); -} - - -GeneralViewSettingsPage::~GeneralViewSettingsPage() -{ -} - -void GeneralViewSettingsPage::applySettings() -{ - ViewProperties props(m_url); // read current view properties - - const bool useGlobalProps = m_globalProps->isChecked(); - - GeneralSettings* settings = DolphinSettings::instance().generalSettings(); - settings->setGlobalViewProps(useGlobalProps); - - if (useGlobalProps) { - // Remember the global view properties by applying the current view properties. - // It is important that GeneralSettings::globalViewProps() is set before - // the class ViewProperties is used, as ViewProperties uses this setting - // to find the destination folder for storing the view properties. - ViewProperties globalProps(m_url); - globalProps.setDirProperties(props); - } - - KConfigGroup globalConfig(KGlobal::config(), "PreviewSettings"); - const int byteCount = m_maxPreviewSize->value() * 1024 * 1024; // value() returns size in MB - globalConfig.writeEntry("MaximumSize", - byteCount, - KConfigBase::Normal | KConfigBase::Global); - globalConfig.writeEntry("UseFileThumbnails", - m_useFileThumbnails->isChecked(), - KConfigBase::Normal | KConfigBase::Global); - globalConfig.sync(); - - settings->setShowSelectionToggle(m_showSelectionToggle->isChecked()); - settings->setShowToolTips(m_showToolTips->isChecked()); -} - -void GeneralViewSettingsPage::restoreDefaults() -{ - GeneralSettings* settings = DolphinSettings::instance().generalSettings(); - settings->setDefaults(); - loadSettings(); -} - -void GeneralViewSettingsPage::loadSettings() -{ - GeneralSettings* settings = DolphinSettings::instance().generalSettings(); - if (settings->globalViewProps()) { - m_globalProps->setChecked(true); - } else { - m_localProps->setChecked(true); - } - - const int min = 1; // MB - const int max = 100; // MB - m_maxPreviewSize->setRange(min, max); - m_maxPreviewSize->setPageStep(10); - m_maxPreviewSize->setSingleStep(1); - m_maxPreviewSize->setTickPosition(QSlider::TicksBelow); - - KConfigGroup globalConfig(KGlobal::config(), "PreviewSettings"); - // TODO: The default value of 5 MB must match with the default value inside - // kdelibs/kio/kio/previewjob.cpp. Maybe a static getter method in PreviewJob - // should be added for getting the default size? - const int maxByteSize = globalConfig.readEntry("MaximumSize", 5 * 1024 * 1024 /* 5 MB */); - int maxMByteSize = maxByteSize / (1024 * 1024); - if (maxMByteSize < 1) { - maxMByteSize = 1; - } else if (maxMByteSize > max) { - maxMByteSize = max; - } - - m_spinBox->setRange(min, max); - m_spinBox->setSingleStep(1); - m_spinBox->setSuffix(" MB"); - - m_maxPreviewSize->setValue(maxMByteSize); - m_spinBox->setValue(m_maxPreviewSize->value()); - - const bool useFileThumbnails = globalConfig.readEntry("UseFileThumbnails", true); - m_useFileThumbnails->setChecked(useFileThumbnails); - - m_showSelectionToggle->setChecked(settings->showSelectionToggle()); - m_showToolTips->setChecked(settings->showToolTips()); -} - -#include "generalviewsettingspage.moc" diff --git a/src/generalviewsettingspage.h b/src/generalviewsettingspage.h deleted file mode 100644 index 904622348..000000000 --- a/src/generalviewsettingspage.h +++ /dev/null @@ -1,73 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2006 by Peter Penz * - * * - * 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 of the License, 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. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#ifndef GENERALVIEWSETTINGSPAGE_H -#define GENERALVIEWSETTINGSPAGE_H - -#include -#include - -class DolphinMainWindow; -class QCheckBox; -class QRadioButton; -class QSlider; -class QSpinBox; - -/** - * @brief Represents the page from the Dolphin Settings which allows - * to modify general settings for the view modes. - */ -class GeneralViewSettingsPage : public ViewSettingsPageBase -{ - Q_OBJECT - -public: - /** - * @param url URL of the currently shown directory, which is used - * to read the viewproperties. - * @param parent Parent widget of the settings page. - */ - GeneralViewSettingsPage(const KUrl& url, QWidget* parent); - virtual ~GeneralViewSettingsPage(); - - /** - * Applies the general settings for the view modes - * The settings are persisted automatically when - * closing Dolphin. - */ - virtual void applySettings(); - - /** Restores the settings to default values. */ - virtual void restoreDefaults(); - -private: - void loadSettings(); - -private: - KUrl m_url; - QRadioButton* m_localProps; - QRadioButton* m_globalProps; - QSlider* m_maxPreviewSize; - QSpinBox* m_spinBox; - QCheckBox* m_useFileThumbnails; - QCheckBox* m_showSelectionToggle; - QCheckBox* m_showToolTips; -}; - -#endif diff --git a/src/iconsizegroupbox.cpp b/src/iconsizegroupbox.cpp deleted file mode 100644 index 82698e7b7..000000000 --- a/src/iconsizegroupbox.cpp +++ /dev/null @@ -1,116 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Peter Penz * - * * - * 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 of the License, 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. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#include "iconsizegroupbox.h" - -#include - -#include -#include -#include -#include -#include -#include -#include - -#include "zoomlevelinfo.h" - -IconSizeGroupBox::IconSizeGroupBox(QWidget* parent) : - QGroupBox(i18nc("@title:group", "Icon Size"), parent), - m_defaultSizeSlider(0), - m_previewSizeSlider(0) -{ - QLabel* defaultLabel = new QLabel(i18nc("@label:listbox", "Default:"), this); - m_defaultSizeSlider = new QSlider(Qt::Horizontal, this); - m_defaultSizeSlider->setPageStep(1); - m_defaultSizeSlider->setTickPosition(QSlider::TicksBelow); - connect(m_defaultSizeSlider, SIGNAL(sliderMoved(int)), - this, SLOT(slotDefaultSliderMoved(int))); - - QLabel* previewLabel = new QLabel(i18nc("@label:listbox", "Preview:"), this); - m_previewSizeSlider = new QSlider(Qt::Horizontal, this); - m_previewSizeSlider->setPageStep(1); - m_previewSizeSlider->setTickPosition(QSlider::TicksBelow); - connect(m_previewSizeSlider, SIGNAL(sliderMoved(int)), - this, SLOT(slotPreviewSliderMoved(int))); - - QGridLayout* layout = new QGridLayout(this); - layout->addWidget(defaultLabel, 0, 0, Qt::AlignRight); - layout->addWidget(m_defaultSizeSlider, 0, 1); - layout->addWidget(previewLabel, 1, 0, Qt::AlignRight); - layout->addWidget(m_previewSizeSlider, 1, 1); -} - -IconSizeGroupBox::~IconSizeGroupBox() -{ -} - -void IconSizeGroupBox::setDefaultSizeRange(int min, int max) -{ - m_defaultSizeSlider->setRange(min, max); -} - -void IconSizeGroupBox::setPreviewSizeRange(int min, int max) -{ - m_previewSizeSlider->setRange(min, max); -} - -void IconSizeGroupBox::setDefaultSizeValue(int value) -{ - m_defaultSizeSlider->setValue(value); -} - -int IconSizeGroupBox::defaultSizeValue() const -{ - return m_defaultSizeSlider->value(); -} - -void IconSizeGroupBox::setPreviewSizeValue(int value) -{ - m_previewSizeSlider->setValue(value); -} - -int IconSizeGroupBox::previewSizeValue() const -{ - return m_previewSizeSlider->value(); -} - -void IconSizeGroupBox::slotDefaultSliderMoved(int value) -{ - showToolTip(m_defaultSizeSlider, value); - emit defaultSizeChanged(value); -} - -void IconSizeGroupBox::slotPreviewSliderMoved(int value) -{ - showToolTip(m_previewSizeSlider, value); - emit previewSizeChanged(value); -} - -void IconSizeGroupBox::showToolTip(QSlider* slider, int value) -{ - const int size = ZoomLevelInfo::iconSizeForZoomLevel(value); - slider->setToolTip(i18ncp("@info:tooltip", "Size: 1 pixel", "Size: %1 pixels", size)); - QPoint global = slider->rect().topLeft(); - global.ry() += slider->height() / 2; - QHelpEvent toolTipEvent(QEvent::ToolTip, QPoint(0, 0), slider->mapToGlobal(global)); - QApplication::sendEvent(slider, &toolTipEvent); -} - -#include "iconsizegroupbox.moc" diff --git a/src/iconsizegroupbox.h b/src/iconsizegroupbox.h deleted file mode 100644 index 3ec51c3a5..000000000 --- a/src/iconsizegroupbox.h +++ /dev/null @@ -1,66 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Peter Penz * - * * - * 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 of the License, 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. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#ifndef ICONSIZEGROUPBOX_H -#define ICONSIZEGROUPBOX_H - -#include - -class QSlider; - -/** - * @short Provides a group box for adjusting the icon sizes. - * - * It is possible to adjust the default icon size and the icon - * size when previews are used. - */ -class IconSizeGroupBox : public QGroupBox -{ - Q_OBJECT - -public: - explicit IconSizeGroupBox(QWidget* parent); - virtual ~IconSizeGroupBox(); - - void setDefaultSizeRange(int min, int max); - void setPreviewSizeRange(int min, int max); - - void setDefaultSizeValue(int value); - int defaultSizeValue() const; - - void setPreviewSizeValue(int value); - int previewSizeValue() const; - -signals: - void defaultSizeChanged(int value); - void previewSizeChanged(int value); - -private slots: - void slotDefaultSliderMoved(int value); - void slotPreviewSliderMoved(int value); - -private: - void showToolTip(QSlider* slider, int value); - -private: - QSlider* m_defaultSizeSlider; - QSlider* m_previewSizeSlider; -}; - -#endif diff --git a/src/iconsviewsettingspage.cpp b/src/iconsviewsettingspage.cpp deleted file mode 100644 index ca43841b8..000000000 --- a/src/iconsviewsettingspage.cpp +++ /dev/null @@ -1,243 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2006 by Peter Penz * - * * - * 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 of the License, 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. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#include "iconsviewsettingspage.h" - -#include "dolphinfontrequester.h" -#include "dolphinsettings.h" -#include "iconsizegroupbox.h" -#include "zoomlevelinfo.h" - -#include "dolphin_iconsmodesettings.h" - -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -IconsViewSettingsPage::IconsViewSettingsPage(QWidget* parent) : - ViewSettingsPageBase(parent), - m_iconSizeGroupBox(0), - m_textWidthBox(0), - m_fontRequester(0), - m_textlinesCountBox(0), - m_arrangementBox(0), - m_gridSpacingBox(0) -{ - const int spacing = KDialog::spacingHint(); - const int margin = KDialog::marginHint(); - const QSizePolicy sizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); - - setSpacing(spacing); - setMargin(margin); - - // Create "Icon" properties - m_iconSizeGroupBox = new IconSizeGroupBox(this); - m_iconSizeGroupBox->setSizePolicy(sizePolicy); - - const int min = ZoomLevelInfo::minimumLevel(); - const int max = ZoomLevelInfo::maximumLevel(); - m_iconSizeGroupBox->setDefaultSizeRange(min, max); - m_iconSizeGroupBox->setPreviewSizeRange(min, max); - - connect(m_iconSizeGroupBox, SIGNAL(defaultSizeChanged(int)), - this, SIGNAL(changed())); - connect(m_iconSizeGroupBox, SIGNAL(previewSizeChanged(int)), - this, SIGNAL(changed())); - - // create 'Text' group for selecting the font, the number of lines - // and the text width - QGroupBox* textGroup = new QGroupBox(i18nc("@title:group", "Text"), this); - textGroup->setSizePolicy(sizePolicy); - - QLabel* fontLabel = new QLabel(i18nc("@label:listbox", "Font:"), textGroup); - m_fontRequester = new DolphinFontRequester(textGroup); - connect(m_fontRequester, SIGNAL(changed()), this, SIGNAL(changed())); - - QLabel* textlinesCountLabel = new QLabel(i18nc("@label:textbox", "Number of lines:"), textGroup); - m_textlinesCountBox = new QSpinBox(textGroup); - m_textlinesCountBox->setMinimum(1); - m_textlinesCountBox->setMaximum(5); - connect(m_textlinesCountBox, SIGNAL(valueChanged(int)), this, SIGNAL(changed())); - - QLabel* textWidthLabel = new QLabel(i18nc("@label:listbox", "Text width:"), textGroup); - m_textWidthBox = new KComboBox(textGroup); - m_textWidthBox->addItem(i18nc("@item:inlistbox Text width", "Small")); - m_textWidthBox->addItem(i18nc("@item:inlistbox Text width", "Medium")); - m_textWidthBox->addItem(i18nc("@item:inlistbox Text width", "Large")); - m_textWidthBox->addItem(i18nc("@item:inlistbox Text width", "Huge")); - connect(m_textWidthBox, SIGNAL(activated(int)), this, SIGNAL(changed())); - - QGridLayout* textGroupLayout = new QGridLayout(textGroup); - textGroupLayout->addWidget(fontLabel, 0, 0, Qt::AlignRight); - textGroupLayout->addWidget(m_fontRequester, 0, 1); - textGroupLayout->addWidget(textlinesCountLabel, 1, 0, Qt::AlignRight); - textGroupLayout->addWidget(m_textlinesCountBox, 1, 1); - textGroupLayout->addWidget(textWidthLabel, 2, 0, Qt::AlignRight); - textGroupLayout->addWidget(m_textWidthBox, 2, 1); - - // create the 'Grid' group for selecting the arrangement and the grid spacing - QGroupBox* gridGroup = new QGroupBox(i18nc("@title:group", "Grid"), this); - gridGroup->setSizePolicy(sizePolicy); - - QLabel* arrangementLabel = new QLabel(i18nc("@label:listbox", "Arrangement:"), gridGroup); - m_arrangementBox = new KComboBox(gridGroup); - m_arrangementBox->addItem(i18nc("@item:inlistbox Arrangement", "Columns")); - m_arrangementBox->addItem(i18nc("@item:inlistbox Arrangement", "Rows")); - connect(m_arrangementBox, SIGNAL(activated(int)), this, SIGNAL(changed())); - - QLabel* gridSpacingLabel = new QLabel(i18nc("@label:listbox", "Grid spacing:"), gridGroup); - m_gridSpacingBox = new KComboBox(gridGroup); - m_gridSpacingBox->addItem(i18nc("@item:inlistbox Grid spacing", "None")); - m_gridSpacingBox->addItem(i18nc("@item:inlistbox Grid spacing", "Small")); - m_gridSpacingBox->addItem(i18nc("@item:inlistbox Grid spacing", "Medium")); - m_gridSpacingBox->addItem(i18nc("@item:inlistbox Grid spacing", "Large")); - connect(m_gridSpacingBox, SIGNAL(activated(int)), this, SIGNAL(changed())); - - QGridLayout* gridGroupLayout = new QGridLayout(gridGroup); - gridGroupLayout->addWidget(arrangementLabel, 0, 0, Qt::AlignRight); - gridGroupLayout->addWidget(m_arrangementBox, 0, 1); - gridGroupLayout->addWidget(gridSpacingLabel, 1, 0, Qt::AlignRight); - gridGroupLayout->addWidget(m_gridSpacingBox, 1, 1); - - // Add a dummy widget with no restriction regarding - // a vertical resizing. This assures that the dialog layout - // is not stretched vertically. - new QWidget(this); - - loadSettings(); -} - -IconsViewSettingsPage::~IconsViewSettingsPage() -{ -} - -void IconsViewSettingsPage::applySettings() -{ - IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings(); - - const int iconSize = ZoomLevelInfo::iconSizeForZoomLevel(m_iconSizeGroupBox->defaultSizeValue()); - const int previewSize = ZoomLevelInfo::iconSizeForZoomLevel(m_iconSizeGroupBox->previewSizeValue()); - settings->setIconSize(iconSize); - settings->setPreviewSize(previewSize); - - const QFont font = m_fontRequester->font(); - const int fontHeight = QFontMetrics(font).height(); - - const int arrangement = (m_arrangementBox->currentIndex() == 0) ? - QListView::LeftToRight : - QListView::TopToBottom; - settings->setArrangement(arrangement); - - const int numberOfTextlines = m_textlinesCountBox->value(); - - const int defaultSize = settings->iconSize(); - int itemWidth = defaultSize; - int itemHeight = defaultSize; - const int textSizeIndex = m_textWidthBox->currentIndex(); - if (arrangement == QListView::TopToBottom) { - itemWidth += TopToBottomBase + textSizeIndex * TopToBottomInc; - itemHeight += fontHeight * numberOfTextlines + 10; - } else { - itemWidth += LeftToRightBase + textSizeIndex * LeftToRightInc; - } - - settings->setItemWidth(itemWidth); - settings->setItemHeight(itemHeight); - - settings->setUseSystemFont(m_fontRequester->mode() == DolphinFontRequester::SystemFont); - settings->setFontFamily(font.family()); - settings->setFontSize(font.pointSize()); - settings->setItalicFont(font.italic()); - settings->setFontWeight(font.weight()); - - settings->setNumberOfTextlines(numberOfTextlines); - - const int index = m_gridSpacingBox->currentIndex(); - if (index == 0) { - // No grid spacing - settings->setGridSpacing(0); - } else { - settings->setGridSpacing(GridSpacingBase + (index - 1) * GridSpacingInc); - } -} - -void IconsViewSettingsPage::restoreDefaults() -{ - IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings(); - settings->setDefaults(); - loadSettings(); -} - -void IconsViewSettingsPage::loadSettings() -{ - IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings(); - - const QSize iconSize(settings->iconSize(), settings->iconSize()); - const int iconSizeValue = ZoomLevelInfo::zoomLevelForIconSize(iconSize); - m_iconSizeGroupBox->setDefaultSizeValue(iconSizeValue); - - const QSize previewSize(settings->previewSize(), settings->previewSize()); - const int previewSizeValue = ZoomLevelInfo::zoomLevelForIconSize(previewSize); - m_iconSizeGroupBox->setPreviewSizeValue(previewSizeValue); - - if (settings->useSystemFont()) { - m_fontRequester->setMode(DolphinFontRequester::SystemFont); - } else { - QFont font(settings->fontFamily(), - settings->fontSize()); - font.setItalic(settings->italicFont()); - font.setWeight(settings->fontWeight()); - m_fontRequester->setMode(DolphinFontRequester::CustomFont); - m_fontRequester->setCustomFont(font); - } - - m_textlinesCountBox->setValue(settings->numberOfTextlines()); - - const bool leftToRightArrangement = (settings->arrangement() == QListView::LeftToRight); - int textWidthIndex = 0; - const int remainingWidth = settings->itemWidth() - settings->iconSize(); - if (leftToRightArrangement) { - textWidthIndex = (remainingWidth - LeftToRightBase) / LeftToRightInc; - } else { - textWidthIndex = (remainingWidth - TopToBottomBase) / TopToBottomInc; - } - // ensure that chosen index is always valid - textWidthIndex = qMax(textWidthIndex, 0); - textWidthIndex = qMin(textWidthIndex, m_textWidthBox->count() - 1); - - m_textWidthBox->setCurrentIndex(textWidthIndex); - m_arrangementBox->setCurrentIndex(leftToRightArrangement ? 0 : 1); - - const int spacing = settings->gridSpacing(); - const int index = (spacing <= 0) ? 0 : 1 + (spacing - GridSpacingBase) / GridSpacingInc; - m_gridSpacingBox->setCurrentIndex(index); -} - -#include "iconsviewsettingspage.moc" diff --git a/src/iconsviewsettingspage.h b/src/iconsviewsettingspage.h deleted file mode 100644 index 75db81e53..000000000 --- a/src/iconsviewsettingspage.h +++ /dev/null @@ -1,88 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2006 by Peter Penz * - * * - * 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 of the License, 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. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#ifndef ICONSVIEWSETTINGSPAGE_H -#define ICONSVIEWSETTINGSPAGE_H - -#include -#include - -class DolphinFontRequester; -class IconSizeGroupBox; -class QCheckBox; -class KComboBox; -class QSpinBox; - -/** - * @brief Tab page for the 'Icons Mode' and 'Previews Mode' settings - * of the Dolphin settings dialog. - * - * Allows to set: - * - icon size - * - preview size - * - text width - * - grid spacing - * - font - * - number of text lines - * - arrangement - * - * @see DolphinIconsViewSettings - */ -class IconsViewSettingsPage : public ViewSettingsPageBase -{ - Q_OBJECT - -public: - IconsViewSettingsPage(QWidget* parent); - virtual ~IconsViewSettingsPage(); - - /** - * Applies the settings for the icons view. - * The settings are persisted automatically when - * closing Dolphin. - */ - virtual void applySettings(); - - /** Restores the settings to default values. */ - virtual void restoreDefaults(); - -private: - void loadSettings(); - -private: - enum - { - GridSpacingBase = 8, - GridSpacingInc = 12, - LeftToRightBase = 128, - LeftToRightInc = 64, - TopToBottomBase = 32, - TopToBottomInc = 32 - }; - - IconSizeGroupBox* m_iconSizeGroupBox; - KComboBox* m_textWidthBox; - DolphinFontRequester* m_fontRequester; - QSpinBox* m_textlinesCountBox; - - KComboBox* m_arrangementBox; - KComboBox* m_gridSpacingBox; -}; - -#endif diff --git a/src/infosidebarpage.cpp b/src/infosidebarpage.cpp deleted file mode 100644 index aa8b20553..000000000 --- a/src/infosidebarpage.cpp +++ /dev/null @@ -1,587 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2006 by Peter Penz * - * * - * 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 of the License, 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. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#include "infosidebarpage.h" - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "dolphinsettings.h" -#include "metadatawidget.h" -#include "metatextlabel.h" -#include "pixmapviewer.h" - -InfoSidebarPage::InfoSidebarPage(QWidget* parent) : - SidebarPage(parent), - m_initialized(false), - m_pendingPreview(false), - m_infoTimer(0), - m_outdatedPreviewTimer(0), - m_shownUrl(), - m_urlCandidate(), - m_fileItem(), - m_selection(), - m_nameLabel(0), - m_preview(0), - m_metaDataWidget(0), - m_metaTextLabel(0) -{ -} - -InfoSidebarPage::~InfoSidebarPage() -{ -} - -QSize InfoSidebarPage::sizeHint() const -{ - QSize size = SidebarPage::sizeHint(); - size.setWidth(minimumSizeHint().width()); - return size; -} - -void InfoSidebarPage::setUrl(const KUrl& url) -{ - SidebarPage::setUrl(url); - if (url.isValid() && !isEqualToShownUrl(url)) { - if (isVisible()) { - cancelRequest(); - m_shownUrl = url; - showItemInfo(); - } else { - m_shownUrl = url; - } - } -} - -void InfoSidebarPage::setSelection(const KFileItemList& selection) -{ - if (!isVisible()) { - return; - } - - if ((selection.count() == 0) && (m_selection.count() == 0)) { - // The selection has not really changed, only the current index. - // QItemSelectionModel emits a signal in this case and it is less - // expensive doing the check this way instead of patching - // DolphinView::emitSelectionChanged(). - return; - } - - m_selection = selection; - - const int count = selection.count(); - if (count == 0) { - if (!isEqualToShownUrl(url())) { - m_shownUrl = url(); - showItemInfo(); - } - } else { - if ((count == 1) && !selection.first().url().isEmpty()) { - m_urlCandidate = selection.first().url(); - } - m_infoTimer->start(); - } -} - -void InfoSidebarPage::requestDelayedItemInfo(const KFileItem& item) -{ - if (!isVisible()) { - return; - } - - cancelRequest(); - - m_fileItem = KFileItem(); - if (item.isNull()) { - // The cursor is above the viewport. If files are selected, - // show information regarding the selection. - if (m_selection.size() > 0) { - m_pendingPreview = false; - m_infoTimer->start(); - } - } else { - const KUrl url = item.url(); - if (url.isValid() && !isEqualToShownUrl(url)) { - m_urlCandidate = item.url(); - m_fileItem = item; - m_infoTimer->start(); - } - } -} - -void InfoSidebarPage::showEvent(QShowEvent* event) -{ - SidebarPage::showEvent(event); - if (!event->spontaneous()) { - if (!m_initialized) { - // do a delayed initialization so that no performance - // penalty is given when Dolphin is started with a closed - // Information Panel - init(); - } - showItemInfo(); - } -} - -void InfoSidebarPage::resizeEvent(QResizeEvent* event) -{ - if (isVisible()) { - // If the text inside the name label or the info label cannot - // get wrapped, then the maximum width of the label is increased - // so that the width of the information sidebar gets increased. - // To prevent this, the maximum width is adjusted to - // the current width of the sidebar. - const int maxWidth = event->size().width() - KDialog::spacingHint() * 4; - m_nameLabel->setMaximumWidth(maxWidth); - - // try to increase the preview as large as possible - m_preview->setSizeHint(QSize(maxWidth, maxWidth)); - m_urlCandidate = m_shownUrl; // reset the URL candidate if a resizing is done - m_infoTimer->start(); - } - - SidebarPage::resizeEvent(event); -} - -void InfoSidebarPage::showItemInfo() -{ - if (!isVisible()) { - return; - } - - cancelRequest(); - - if (showMultipleSelectionInfo()) { - KIconLoader iconLoader; - QPixmap icon = iconLoader.loadIcon("dialog-information", - KIconLoader::NoGroup, - KIconLoader::SizeEnormous); - m_preview->setPixmap(icon); - setNameLabelText(i18ncp("@info", "%1 item selected", "%1 items selected", m_selection.count())); - m_shownUrl = KUrl(); - } else { - const KFileItem item = fileItem(); - const KUrl itemUrl = item.url(); - if (!applyPlace(itemUrl)) { - // try to get a preview pixmap from the item... - m_pendingPreview = true; - - // Mark the currently shown preview as outdated. This is done - // with a small delay to prevent a flickering when the next preview - // can be shown within a short timeframe. - m_outdatedPreviewTimer->start(); - - KIO::PreviewJob* job = KIO::filePreview(KFileItemList() << item, - m_preview->width(), - m_preview->height(), - 0, - 0, - false, - true); - - connect(job, SIGNAL(gotPreview(const KFileItem&, const QPixmap&)), - this, SLOT(showPreview(const KFileItem&, const QPixmap&))); - connect(job, SIGNAL(failed(const KFileItem&)), - this, SLOT(showIcon(const KFileItem&))); - - setNameLabelText(itemUrl.fileName()); - } - } - - showMetaInfo(); -} - -void InfoSidebarPage::slotInfoTimeout() -{ - m_shownUrl = m_urlCandidate; - showItemInfo(); -} - -void InfoSidebarPage::markOutdatedPreview() -{ - KIconEffect iconEffect; - QPixmap disabledPixmap = iconEffect.apply(m_preview->pixmap(), - KIconLoader::Desktop, - KIconLoader::DisabledState); - m_preview->setPixmap(disabledPixmap); -} - -void InfoSidebarPage::showIcon(const KFileItem& item) -{ - m_outdatedPreviewTimer->stop(); - m_pendingPreview = false; - if (!applyPlace(item.url())) { - m_preview->setPixmap(item.pixmap(KIconLoader::SizeEnormous)); - } -} - -void InfoSidebarPage::showPreview(const KFileItem& item, - const QPixmap& pixmap) -{ - m_outdatedPreviewTimer->stop(); - - Q_UNUSED(item); - if (m_pendingPreview) { - m_preview->setPixmap(pixmap); - m_pendingPreview = false; - } -} - -void InfoSidebarPage::slotFileRenamed(const QString& source, const QString& dest) -{ - if (m_shownUrl == KUrl(source)) { - // the currently shown file has been renamed, hence update the item information - // for the renamed file - KFileItem item(KFileItem::Unknown, KFileItem::Unknown, KUrl(dest)); - requestDelayedItemInfo(item); - } -} - -void InfoSidebarPage::slotFilesAdded(const QString& directory) -{ - if (m_shownUrl == KUrl(directory)) { - // If the 'trash' icon changes because the trash has been emptied or got filled, - // the signal filesAdded("trash:/") will be emitted. - KFileItem item(KFileItem::Unknown, KFileItem::Unknown, KUrl(directory)); - requestDelayedItemInfo(item); - } -} - -void InfoSidebarPage::slotFilesChanged(const QStringList& files) -{ - foreach (const QString& fileName, files) { - if (m_shownUrl == KUrl(fileName)) { - showItemInfo(); - break; - } - } -} - -void InfoSidebarPage::slotFilesRemoved(const QStringList& files) -{ - foreach (const QString& fileName, files) { - if (m_shownUrl == KUrl(fileName)) { - // the currently shown item has been removed, show - // the parent directory as fallback - m_shownUrl = url(); - showItemInfo(); - break; - } - } -} - -void InfoSidebarPage::slotEnteredDirectory(const QString& directory) -{ - if (m_shownUrl == KUrl(directory)) { - KFileItem item(KFileItem::Unknown, KFileItem::Unknown, KUrl(directory)); - requestDelayedItemInfo(item); - } -} - -void InfoSidebarPage::slotLeftDirectory(const QString& directory) -{ - if (m_shownUrl == KUrl(directory)) { - // The signal 'leftDirectory' is also emitted when a media - // has been unmounted. In this case no directory change will be - // done in Dolphin, but the Information Panel must be updated to - // indicate an invalid directory. - m_shownUrl = url(); - showItemInfo(); - } -} - -bool InfoSidebarPage::applyPlace(const KUrl& url) -{ - KFilePlacesModel* placesModel = DolphinSettings::instance().placesModel(); - int count = placesModel->rowCount(); - - for (int i = 0; i < count; ++i) { - QModelIndex index = placesModel->index(i, 0); - - if (url.equals(placesModel->url(index), KUrl::CompareWithoutTrailingSlash)) { - setNameLabelText(placesModel->text(index)); - m_preview->setPixmap(placesModel->icon(index).pixmap(128, 128)); - return true; - } - } - - return false; -} - -void InfoSidebarPage::cancelRequest() -{ - m_infoTimer->stop(); -} - -void InfoSidebarPage::showMetaInfo() -{ - m_metaTextLabel->clear(); - - if (showMultipleSelectionInfo()) { - if (m_metaDataWidget != 0) { - KUrl::List urls; - foreach (const KFileItem& item, m_selection) { - urls.append(item.targetUrl()); - } - m_metaDataWidget->setFiles(urls); - } - - quint64 totalSize = 0; - foreach (const KFileItem& item, m_selection) { - // Only count the size of files, not dirs to match what - // DolphinViewContainer::selectionStatusBarText() does. - if (!item.isDir() && !item.isLink()) { - totalSize += item.size(); - } - } - m_metaTextLabel->add(i18nc("@label", "Total size:"), KIO::convertSize(totalSize)); - } else { - const KFileItem item = fileItem(); - if (item.isDir()) { - m_metaTextLabel->add(i18nc("@label", "Type:"), i18nc("@label", "Folder")); - m_metaTextLabel->add(i18nc("@label", "Modified:"), item.timeString()); - } else { - m_metaTextLabel->add(i18nc("@label", "Type:"), item.mimeComment()); - - m_metaTextLabel->add(i18nc("@label", "Size:"), KIO::convertSize(item.size())); - m_metaTextLabel->add(i18nc("@label", "Modified:"), item.timeString()); - - if (item.isLocalFile()) { - // TODO: See convertMetaInfo below, find a way to display only interesting information - // in a readable way - const KFileMetaInfo::WhatFlags flags = KFileMetaInfo::Fastest | - KFileMetaInfo::TechnicalInfo | - KFileMetaInfo::ContentInfo; - const QString path = item.url().path(); - const KFileMetaInfo fileMetaInfo(path, QString(), flags); - if (fileMetaInfo.isValid()) { - const QHash& items = fileMetaInfo.items(); - QHash::const_iterator it = items.constBegin(); - const QHash::const_iterator end = items.constEnd(); - QString labelText; - while (it != end) { - const KFileMetaInfoItem& metaInfoItem = it.value(); - const QVariant& value = metaInfoItem.value(); - if (value.isValid() && convertMetaInfo(metaInfoItem.name(), labelText)) { - m_metaTextLabel->add(labelText, value.toString()); - } - ++it; - } - } - } - } - - if (m_metaDataWidget != 0) { - m_metaDataWidget->setFile(item.targetUrl()); - } - } -} - -bool InfoSidebarPage::convertMetaInfo(const QString& key, QString& text) const -{ - struct MetaKey { - const char* key; - QString text; - }; - - // sorted list of keys, where its data should be shown - static const MetaKey keys[] = { - { "http://freedesktop.org/standards/xesam/1.0/core#album", i18nc("@label", "Album:") }, - { "http://freedesktop.org/standards/xesam/1.0/core#artist", i18nc("@label", "Artist:") }, - { "http://freedesktop.org/standards/xesam/1.0/core#genre", i18nc("@label", "Genre:") }, - { "http://freedesktop.org/standards/xesam/1.0/core#height", i18nc("@label", "Height:") }, - { "http://freedesktop.org/standards/xesam/1.0/core#lineCount", i18nc("@label", "Lines:") }, - { "http://freedesktop.org/standards/xesam/1.0/core#title", i18nc("@label", "Title:") }, - { "http://freedesktop.org/standards/xesam/1.0/core#type", i18nc("@label", "Type:") }, - { "http://freedesktop.org/standards/xesam/1.0/core#trackNumber", i18nc("@label", "Track:") }, - { "http://freedesktop.org/standards/xesam/1.0/core#width", i18nc("@label", "Width:") } - }; - - // do a binary search for the key... - int top = 0; - int bottom = sizeof(keys) / sizeof(MetaKey) - 1; - while (top <= bottom) { - const int middle = (top + bottom) / 2; - const int result = key.compare(keys[middle].key); - if (result < 0) { - bottom = middle - 1; - } else if (result > 0) { - top = middle + 1; - } else { - text = keys[middle].text; - return true; - } - } - - return false; -} - -KFileItem InfoSidebarPage::fileItem() const -{ - if (!m_fileItem.isNull()) { - return m_fileItem; - } - - if (!m_selection.isEmpty()) { - Q_ASSERT(m_selection.count() == 1); - return m_selection.first(); - } - - // no item is hovered and no selection has been done: provide - // an item for the directory represented by m_shownUrl - KFileItem item(KFileItem::Unknown, KFileItem::Unknown, m_shownUrl); - item.refresh(); - return item; -} - -bool InfoSidebarPage::showMultipleSelectionInfo() const -{ - return m_fileItem.isNull() && (m_selection.count() > 1); -} - -bool InfoSidebarPage::isEqualToShownUrl(const KUrl& url) const -{ - return m_shownUrl.equals(url, KUrl::CompareWithoutTrailingSlash); -} - -void InfoSidebarPage::setNameLabelText(const QString& text) -{ - QTextOption textOption; - textOption.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere); - - QTextLayout textLayout(text); - textLayout.setFont(m_nameLabel->font()); - textLayout.setTextOption(textOption); - - QString wrappedText; - wrappedText.reserve(text.length()); - - // wrap the text to fit into the width of m_nameLabel - textLayout.beginLayout(); - QTextLine line = textLayout.createLine(); - while (line.isValid()) { - line.setLineWidth(m_nameLabel->width()); - wrappedText += text.mid(line.textStart(), line.textLength()); - - line = textLayout.createLine(); - if (line.isValid()) { - wrappedText += QChar::LineSeparator; - } - } - textLayout.endLayout(); - - m_nameLabel->setText(wrappedText); -} - -void InfoSidebarPage::init() -{ - const int spacing = KDialog::spacingHint(); - - m_infoTimer = new QTimer(this); - m_infoTimer->setInterval(300); - m_infoTimer->setSingleShot(true); - connect(m_infoTimer, SIGNAL(timeout()), - this, SLOT(slotInfoTimeout())); - - // Initialize timer for disabling an outdated preview with a small - // delay. This prevents flickering if the new preview can be generated - // within a very small timeframe. - m_outdatedPreviewTimer = new QTimer(this); - m_outdatedPreviewTimer->setInterval(300); - m_outdatedPreviewTimer->setSingleShot(true); - connect(m_outdatedPreviewTimer, SIGNAL(timeout()), - this, SLOT(markOutdatedPreview())); - - QVBoxLayout* layout = new QVBoxLayout; - layout->setSpacing(spacing); - - // name - m_nameLabel = new QLabel(this); - QFont font = m_nameLabel->font(); - font.setBold(true); - m_nameLabel->setFont(font); - m_nameLabel->setAlignment(Qt::AlignHCenter); - m_nameLabel->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); - - // preview - m_preview = new PixmapViewer(this); - m_preview->setMinimumWidth(KIconLoader::SizeEnormous + KIconLoader::SizeMedium); - m_preview->setMinimumHeight(KIconLoader::SizeEnormous); - - if (MetaDataWidget::metaDataAvailable()) { - // rating, comment and tags - m_metaDataWidget = new MetaDataWidget(this); - m_metaDataWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); - } - - // general meta text information - m_metaTextLabel = new MetaTextLabel(this); - m_metaTextLabel->setMinimumWidth(spacing); - m_metaTextLabel->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); - - layout->addWidget(m_nameLabel); - layout->addWidget(new KSeparator(this)); - layout->addWidget(m_preview); - layout->addWidget(new KSeparator(this)); - if (m_metaDataWidget != 0) { - layout->addWidget(m_metaDataWidget); - layout->addWidget(new KSeparator(this)); - } - layout->addWidget(m_metaTextLabel); - - // ensure that widgets in the information side bar are aligned towards the top - layout->addStretch(1); - setLayout(layout); - - org::kde::KDirNotify* dirNotify = new org::kde::KDirNotify(QString(), QString(), - QDBusConnection::sessionBus(), this); - connect(dirNotify, SIGNAL(FileRenamed(QString, QString)), SLOT(slotFileRenamed(QString, QString))); - connect(dirNotify, SIGNAL(FilesAdded(QString)), SLOT(slotFilesAdded(QString))); - connect(dirNotify, SIGNAL(FilesChanged(QStringList)), SLOT(slotFilesChanged(QStringList))); - connect(dirNotify, SIGNAL(FilesRemoved(QStringList)), SLOT(slotFilesRemoved(QStringList))); - connect(dirNotify, SIGNAL(enteredDirectory(QString)), SLOT(slotEnteredDirectory(QString))); - connect(dirNotify, SIGNAL(leftDirectory(QString)), SLOT(slotLeftDirectory(QString))); - - m_initialized = true; -} - -#include "infosidebarpage.moc" diff --git a/src/infosidebarpage.h b/src/infosidebarpage.h deleted file mode 100644 index e6f511714..000000000 --- a/src/infosidebarpage.h +++ /dev/null @@ -1,194 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2006 by Peter Penz * - * * - * 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 of the License, 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. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#ifndef INFOSIDEBARPAGE_H -#define INFOSIDEBARPAGE_H - -#include - -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -class QPixmap; -class QString; -class KFileItem; -class QLabel; -class PixmapViewer; -class MetaDataWidget; -class MetaTextLabel; - -/** - * @brief Sidebar for showing meta information of one ore more selected items. - */ -class InfoSidebarPage : public SidebarPage -{ - Q_OBJECT - -public: - explicit InfoSidebarPage(QWidget* parent = 0); - virtual ~InfoSidebarPage(); - - /** @see QWidget::sizeHint() */ - virtual QSize sizeHint() const; - -public slots: - /** @see SidebarPage::setUrl() */ - virtual void setUrl(const KUrl& url); - - /** - * This is invoked to inform the sidebar that the user has selected a new - * set of items. - */ - void setSelection(const KFileItemList& selection); - - /** - * Does a delayed request of information for the item \a item. - * If within this delay InfoSidebarPage::setUrl() or InfoSidebarPage::setSelection() - * are invoked, then the request will be skipped. Requesting a delayed item information - * makes sense when hovering items. - */ - void requestDelayedItemInfo(const KFileItem& item); - -protected: - /** @see QWidget::showEvent() */ - virtual void showEvent(QShowEvent* event); - - /** @see QWidget::resizeEvent() */ - virtual void resizeEvent(QResizeEvent* event); - -private slots: - /** - * Shows the information for the item of the URL which has been provided by - * InfoSidebarPage::requestItemInfo() and provides default actions. - */ - void showItemInfo(); - - /** - * Triggered if the request for item information has timed out. - * @see InfoSidebarPage::requestDelayedItemInfo() - */ - void slotInfoTimeout(); - - /** - * Marks the currently shown preview as outdated - * by greying the content. - */ - void markOutdatedPreview(); - - /** - * Is invoked if no preview is available for the item. In this - * case the icon will be shown. - */ - void showIcon(const KFileItem& item); - - /** - * Is invoked if a preview is available for the item. The preview - * \a pixmap is shown inside the info page. - */ - void showPreview(const KFileItem& item, const QPixmap& pixmap); - - void slotFileRenamed(const QString& source, const QString& dest); - void slotFilesAdded(const QString& directory); - void slotFilesChanged(const QStringList& files); - void slotFilesRemoved(const QStringList& files); - void slotEnteredDirectory(const QString& directory); - void slotLeftDirectory(const QString& directory); - -private: - /** - * Checks whether the an URL is repesented by a place. If yes, - * then the place icon and name are shown instead of a preview. - * @return True, if the URL represents exactly a place. - * @param url The url to check. - */ - bool applyPlace(const KUrl& url); - - /** Assures that any pending item information request is cancelled. */ - void cancelRequest(); - - /** - * Shows the meta information for the current shown item inside - * a label. - */ - void showMetaInfo(); - - /** - * Converts the meta key \a key to a readable format into \a text. - * Returns true, if the string \a key represents a meta information - * that should be shown. If false is returned, \a text is not modified. - */ - bool convertMetaInfo(const QString& key, QString& text) const; - - /** - * Returns the item for file where the preview and meta information - * should be received, if InfoSidebarPage::showMultipleSelectionInfo() - * returns false. - */ - KFileItem fileItem() const; - - /** - * Returns true, if the meta information should be shown for - * the multiple selected items that are stored in - * m_selection. If true is returned, it is assured that - * m_selection.count() > 1. If false is returned, the meta - * information should be shown for the file - * InfosidebarPage::fileUrl(); - */ - bool showMultipleSelectionInfo() const; - - /** - * Returns true, if \a url is equal to the shown URL m_shownUrl. - */ - bool isEqualToShownUrl(const KUrl& url) const; - - /** - * Sets the text for the label \a m_nameLabel and assures that the - * text is split in a way that it can be wrapped within the - * label width (QLabel::setWordWrap() does not work if the - * text represents one extremely long word). - */ - void setNameLabelText(const QString& text); - - void init(); - -private: - bool m_initialized; - bool m_pendingPreview; - QTimer* m_infoTimer; - QTimer* m_outdatedPreviewTimer; - KUrl m_shownUrl; // URL that is shown as info - KUrl m_urlCandidate; // URL candidate that will replace m_shownURL after a delay - KFileItem m_fileItem; // file item for m_shownUrl if available (otherwise null) - KFileItemList m_selection; - - QLabel* m_nameLabel; - PixmapViewer* m_preview; - MetaDataWidget* m_metaDataWidget; - MetaTextLabel* m_metaTextLabel; -}; - -#endif // INFOSIDEBARPAGE_H diff --git a/src/kcmdolphin.cpp b/src/kcmdolphin.cpp index f980fa502..21883e76a 100644 --- a/src/kcmdolphin.cpp +++ b/src/kcmdolphin.cpp @@ -19,10 +19,10 @@ #include "kcmdolphin.h" -#include "columnviewsettingspage.h" -#include "detailsviewsettingspage.h" -#include "generalviewsettingspage.h" -#include "iconsviewsettingspage.h" +#include "settings/columnviewsettingspage.h" +#include "settings/detailsviewsettingspage.h" +#include "settings/generalviewsettingspage.h" +#include "settings/iconsviewsettingspage.h" #include #include diff --git a/src/kformattedballoontipdelegate.cpp b/src/kformattedballoontipdelegate.cpp deleted file mode 100644 index 140c90ef4..000000000 --- a/src/kformattedballoontipdelegate.cpp +++ /dev/null @@ -1,129 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2008 by Fredrik Höglund * - * Copyright (C) 2008 by Konstantin Heil * - * * - * 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 of the License, 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. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - *******************************************************************************/ - -#include "kformattedballoontipdelegate.h" -#include -#include -#include -#include - -KFormattedBalloonTipDelegate::KFormattedBalloonTipDelegate() -{ -} - -KFormattedBalloonTipDelegate::~KFormattedBalloonTipDelegate() -{ -} - -QSize KFormattedBalloonTipDelegate::sizeHint(const KStyleOptionToolTip *option, const KToolTipItem *item) const -{ - QTextDocument doc; - doc.setHtml(item->text()); - const QIcon icon = item->icon(); - - const QSize iconSize = icon.isNull() ? QSize(0, 0) : icon.actualSize(option->decorationSize); - const QSize docSize = doc.size().toSize(); - QSize contentSize = iconSize + docSize; - - // assure that the content height is large enough for the icon and the document - contentSize.setHeight(iconSize.height() > doc.size().height() ? iconSize.height() : doc.size().height()); - return contentSize + QSize(Border * 3, Border * 2); -} - -void KFormattedBalloonTipDelegate::paint(QPainter *painter, - const KStyleOptionToolTip *option, - const KToolTipItem *item) const -{ - QPainterPath path = createPath(*option); - if (haveAlphaChannel()) { - painter->setRenderHint(QPainter::Antialiasing); - painter->translate(.5, .5); - } - - const QColor toColor = option->palette.brush(QPalette::ToolTipBase).color(); - const QColor fromColor = KColorScheme::shade(toColor, KColorScheme::LightShade, 0.2); - - QLinearGradient gradient(option->rect.topLeft(), option->rect.bottomLeft()); - gradient.setColorAt(0.0, fromColor); - gradient.setColorAt(1.0, toColor); - painter->setPen(Qt::NoPen); - painter->setBrush(gradient); - - painter->drawPath(path); - - const QIcon icon = item->icon(); - int x = Border; - const int y = Border; - if (!icon.isNull()) { - const QSize iconSize = icon.actualSize(option->decorationSize); - const QPoint pos(x + option->rect.x(), y + option->rect.y()); - painter->drawPixmap(pos, icon.pixmap(iconSize)); - x += iconSize.width() + Border; - } - - QTextDocument doc; - doc.setHtml(item->text()); - QPixmap bitmap(doc.size().toSize()); - bitmap.fill(Qt::transparent); - QPainter p(&bitmap); - doc.drawContents(&p); - - const QRect docRect(QPoint(x, y), doc.size().toSize()); - painter->drawPixmap(docRect, bitmap); -} - -QRegion KFormattedBalloonTipDelegate::inputShape(const KStyleOptionToolTip *option) const -{ - QBitmap bitmap(option->rect.size()); - bitmap.fill(Qt::color0); - - QPainter p(&bitmap); - p.setPen(QPen(Qt::color1, 1)); - p.setBrush(Qt::color1); - p.drawPath(createPath(*option)); - - return QRegion(bitmap); -} - -QRegion KFormattedBalloonTipDelegate::shapeMask(const KStyleOptionToolTip *option) const -{ - return inputShape(option); -} - -static inline void arc(QPainterPath &path, qreal cx, qreal cy, qreal radius, qreal angle, qreal sweeplength) -{ - path.arcTo(cx-radius, cy-radius, radius * 2, radius * 2, angle, sweeplength); -} - -QPainterPath KFormattedBalloonTipDelegate::createPath(const KStyleOptionToolTip& option) const -{ - const QRect rect = option.rect; - const qreal radius = 5; - - QPainterPath path; - path.moveTo(rect.left(), rect.top() + radius); - arc(path, rect.left() + radius, rect.top() + radius, radius, 180, -90); - arc(path, rect.right() - radius, rect.top() + radius, radius, 90, -90); - arc(path, rect.right() - radius, rect.bottom() - radius, radius, 0, -90); - arc(path, rect.left() + radius, rect.bottom() - radius, radius, 270, -90); - path.closeSubpath(); - - return path; -} diff --git a/src/kformattedballoontipdelegate.h b/src/kformattedballoontipdelegate.h deleted file mode 100644 index 452b38a69..000000000 --- a/src/kformattedballoontipdelegate.h +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2008 by Fredrik Höglund * - * Copyright (C) 2008 by Konstantin Heil * - * * - * 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 of the License, 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. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - *******************************************************************************/ - -#ifndef KFORMATTEDBALLOONTIPDELEGATE_H -#define KFORMATTEDBALLOONTIPDELEGATE_H - -#include "ktooltip.h" -#include - -class KFormattedBalloonTipDelegate : public KToolTipDelegate -{ -public: - KFormattedBalloonTipDelegate(); - virtual ~KFormattedBalloonTipDelegate(); - - virtual QSize sizeHint(const KStyleOptionToolTip *option, const KToolTipItem *item) const; - virtual void paint(QPainter *painter, const KStyleOptionToolTip *option, const KToolTipItem *item) const; - virtual QRegion inputShape(const KStyleOptionToolTip *option) const; - virtual QRegion shapeMask(const KStyleOptionToolTip *option) const; - -private: - QPainterPath createPath(const KStyleOptionToolTip& option) const; - -private: - enum { Border = 8 }; -}; - -#endif diff --git a/src/ktooltip.cpp b/src/ktooltip.cpp deleted file mode 100644 index a0126fbff..000000000 --- a/src/ktooltip.cpp +++ /dev/null @@ -1,558 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Fredrik Höglund * - * * - * 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 of the License, 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. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#include "ktooltip.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef Q_WS_X11 -# include -# include -# include -# include -#endif - -#include "ktooltip_p.h" - - -// compile with XShape older than 1.0 -#ifndef ShapeInput -const int ShapeInput = 2; -#endif - - -class KToolTipItemPrivate -{ -public: - QMap map; - int type; -}; - -KToolTipItem::KToolTipItem(const QString &text, int type) - : d(new KToolTipItemPrivate) -{ - d->map[Qt::DisplayRole] = text; - d->type = type; -} - -KToolTipItem::KToolTipItem(const QIcon &icon, const QString &text, int type) - : d(new KToolTipItemPrivate) -{ - d->map[Qt::DecorationRole] = icon; - d->map[Qt::DisplayRole] = text; - d->type = type; -} - -KToolTipItem::~KToolTipItem() -{ - delete d; -} - -int KToolTipItem::type() const -{ - return d->type; -} - -QString KToolTipItem::text() const -{ - return data(Qt::DisplayRole).toString(); -} - -QIcon KToolTipItem::icon() const -{ - return qvariant_cast(data(Qt::DecorationRole)); -} - -QVariant KToolTipItem::data(int role) const -{ - return d->map.value(role); -} - -void KToolTipItem::setData(int role, const QVariant &data) -{ - d->map[role] = data; - KToolTipManager::instance()->update(); -} - - - -// ---------------------------------------------------------------------------- - - -KStyleOptionToolTip::KStyleOptionToolTip() - : fontMetrics(QApplication::font()) -{ -} - - -// ---------------------------------------------------------------------------- - - - -KToolTipDelegate::KToolTipDelegate() : QObject() -{ -} - -KToolTipDelegate::~KToolTipDelegate() -{ -} - -QSize KToolTipDelegate::sizeHint(const KStyleOptionToolTip *option, const KToolTipItem *item) const -{ - QSize size; - size.rwidth() = option->fontMetrics.width(item->text()); - size.rheight() = option->fontMetrics.lineSpacing(); - - QIcon icon = item->icon(); - if (!icon.isNull()) { - const QSize iconSize = icon.actualSize(option->decorationSize); - size.rwidth() += iconSize.width() + 4; - size.rheight() = qMax(size.height(), iconSize.height()); - } - - return size + QSize(20, 20); - -} - -void KToolTipDelegate::paint(QPainter *painter, const KStyleOptionToolTip *option, - const KToolTipItem *item) const -{ - bool haveAlpha = haveAlphaChannel(); - painter->setRenderHint(QPainter::Antialiasing); - - QPainterPath path; - if (haveAlpha) - path.addRoundRect(option->rect.adjusted(0, 0, -1, -1), 25); - else - path.addRect(option->rect.adjusted(0, 0, -1, -1)); - - QColor color = option->palette.color(QPalette::ToolTipBase); - QColor from = color.lighter(105); - QColor to = color.darker(120); - - QLinearGradient gradient(0, 0, 0, 1); - gradient.setCoordinateMode(QGradient::ObjectBoundingMode); - gradient.setColorAt(0, from); - gradient.setColorAt(1, to); - - painter->translate(.5, .5); - painter->setPen(QPen(Qt::black, 1)); - painter->setBrush(gradient); - painter->drawPath(path); - painter->translate(-.5, -.5); - - if (haveAlpha) { - QLinearGradient mask(0, 0, 0, 1); - gradient.setCoordinateMode(QGradient::ObjectBoundingMode); - gradient.setColorAt(0, QColor(0, 0, 0, 192)); - gradient.setColorAt(1, QColor(0, 0, 0, 72)); - painter->setCompositionMode(QPainter::CompositionMode_DestinationIn); - painter->fillRect(option->rect, gradient); - painter->setCompositionMode(QPainter::CompositionMode_SourceOver); - } - - QRect textRect = option->rect.adjusted(10, 10, -10, -10); - - QIcon icon = item->icon(); - if (!icon.isNull()) { - const QSize iconSize = icon.actualSize(option->decorationSize); - painter->drawPixmap(textRect.topLeft(), icon.pixmap(iconSize)); - textRect.adjust(iconSize.width() + 4, 0, 0, 0); - } - painter->drawText(textRect, Qt::AlignLeft | Qt::AlignVCenter, item->text()); -} - -QRegion KToolTipDelegate::inputShape(const KStyleOptionToolTip *option) const -{ - return QRegion(option->rect); -} - -QRegion KToolTipDelegate::shapeMask(const KStyleOptionToolTip *option) const -{ - return QRegion(option->rect); -} - -bool KToolTipDelegate::haveAlphaChannel() const -{ - return KToolTipManager::instance()->haveAlphaChannel(); -} - - - -// ---------------------------------------------------------------------------- - - - -class KAbstractToolTipLabel -{ -public: - KAbstractToolTipLabel() {} - virtual ~KAbstractToolTipLabel() {} - - virtual void showTip(const QPoint &pos, const KToolTipItem *item) = 0; - virtual void moveTip(const QPoint &pos) = 0; - virtual void hideTip() = 0; - -protected: - KStyleOptionToolTip styleOption() const; - KToolTipDelegate *delegate() const; -}; - -KStyleOptionToolTip KAbstractToolTipLabel::styleOption() const -{ - KStyleOptionToolTip option; - KToolTipManager::instance()->initStyleOption(&option); - return option; -} - -KToolTipDelegate *KAbstractToolTipLabel::delegate() const -{ - return KToolTipManager::instance()->delegate(); -} - - -// ---------------------------------------------------------------------------- - - - -class QWidgetLabel : public QWidget, public KAbstractToolTipLabel -{ -public: - QWidgetLabel() : QWidget(0, Qt::ToolTip) {} - void showTip(const QPoint &pos, const KToolTipItem *item); - void moveTip(const QPoint &pos); - void hideTip(); - -private: - void paintEvent(QPaintEvent*); - QSize sizeHint() const; - -private: - const KToolTipItem *currentItem; -}; - -void QWidgetLabel::showTip(const QPoint &pos, const KToolTipItem *item) -{ - currentItem = item; - move(pos); - show(); -} - -void QWidgetLabel::hideTip() -{ - hide(); - currentItem = 0; -} - -void QWidgetLabel::moveTip(const QPoint &pos) -{ - move(pos); -} - -void QWidgetLabel::paintEvent(QPaintEvent*) -{ - KStyleOptionToolTip option = styleOption(); - option.rect = rect(); - - setMask(delegate()->shapeMask(&option)); - - QPainter p(this); - p.setFont(option.font); - p.setPen(QPen(option.palette.brush(QPalette::Text), 0)); - delegate()->paint(&p, &option, currentItem); -} - -QSize QWidgetLabel::sizeHint() const -{ - if (!currentItem) - return QSize(); - - KStyleOptionToolTip option = styleOption(); - return delegate()->sizeHint(&option, currentItem); -} - - - -// ---------------------------------------------------------------------------- - - - -#ifdef Q_WS_X11 - -// X11 specific label that displays the tip in an ARGB window. -class ArgbLabel : public KAbstractToolTipLabel -{ -public: - ArgbLabel(Visual *visual, int depth); - ~ArgbLabel(); - - void showTip(const QPoint &pos, const KToolTipItem *item); - void moveTip(const QPoint &pos); - void hideTip(); - -private: - Window window; - Colormap colormap; - Picture picture; - bool mapped; -}; - -ArgbLabel::ArgbLabel(Visual *visual, int depth) -{ - Display *dpy = QX11Info::display(); - Window root = QX11Info::appRootWindow(); - colormap = XCreateColormap(dpy, QX11Info::appRootWindow(), visual, AllocNone); - - XSetWindowAttributes attr; - attr.border_pixel = 0; - attr.background_pixel = 0; - attr.colormap = colormap; - attr.override_redirect = True; - - window = XCreateWindow(dpy, root, 0, 0, 1, 1, 0, depth, InputOutput, visual, - CWBorderPixel | CWBackPixel | CWColormap | - CWOverrideRedirect, &attr); - - // ### TODO: Set the WM hints so KWin can identify this window as a - // tooltip. - - XRenderPictFormat *format = XRenderFindVisualFormat(dpy, visual); - picture = XRenderCreatePicture(dpy, window, format, 0, 0); - - mapped = false; -} - -ArgbLabel::~ArgbLabel() -{ - Display *dpy = QX11Info::display(); - XRenderFreePicture(dpy, picture); - XDestroyWindow(dpy, window); - XFreeColormap(dpy, colormap); -} - -void ArgbLabel::showTip(const QPoint &pos, const KToolTipItem *item) -{ - Display *dpy = QX11Info::display(); - KStyleOptionToolTip option = styleOption(); - const QSize size = delegate()->sizeHint(&option, item); - option.rect = QRect(QPoint(), size); - - QPixmap pixmap(size); - pixmap.fill(Qt::transparent); - - QPainter p(&pixmap); - p.setFont(option.font); - p.setPen(QPen(option.palette.brush(QPalette::Text), 0)); - delegate()->paint(&p, &option, item); - - // Resize, position and show the window. - XMoveResizeWindow(dpy, window, pos.x(), pos.y(), size.width(), size.height()); - - if (KToolTipManager::instance()->haveAlphaChannel()) { - const QRegion region = delegate()->inputShape(&option); - XShapeCombineRegion(dpy, window, ShapeInput, 0, 0, region.handle(), ShapeSet); - } else { - const QRegion region = delegate()->shapeMask(&option); - XShapeCombineRegion(dpy, window, ShapeBounding, 0, 0, region.handle(), ShapeSet); - } - - XMapWindow(dpy, window); - - // Blit the pixmap with the tip contents to the window. - // Since the window is override-redirect and an ARGB32 window, - // which always has an offscreen pixmap, there's no need to - // wait for an Expose event, or to process those. - XRenderComposite(dpy, PictOpSrc, pixmap.x11PictureHandle(), None, - picture, 0, 0, 0, 0, 0, 0, size.width(), size.height()); - - mapped = true; -} - -void ArgbLabel::moveTip(const QPoint &pos) -{ - if (mapped) - XMoveWindow(QX11Info::display(), window, pos.x(), pos.y()); -} - -void ArgbLabel::hideTip() -{ - if (mapped) { - Display *dpy = QX11Info::display(); - XUnmapWindow(dpy, window); - mapped = false; - } -} - -#endif // Q_WS_X11 - - - - -// ---------------------------------------------------------------------------- - - - - -KToolTipManager *KToolTipManager::s_instance = 0; - -KToolTipManager::KToolTipManager() - : label(0), currentItem(0), m_delegate(0) -{ -#ifdef Q_WS_X11 - Display *dpy = QX11Info::display(); - int screen = DefaultScreen(dpy); - int depth = DefaultDepth(dpy, screen); - Visual *visual = DefaultVisual(dpy, screen); - net_wm_cm_s0 = XInternAtom(dpy, "_NET_WM_CM_S0", False); - haveArgbVisual = false; - - int nvi; - XVisualInfo templ; - templ.screen = screen; - templ.depth = 32; - templ.c_class = TrueColor; - XVisualInfo *xvi = XGetVisualInfo(dpy, VisualScreenMask | VisualDepthMask | - VisualClassMask, &templ, &nvi); - - for (int i = 0; i < nvi; ++i) - { - XRenderPictFormat *format = XRenderFindVisualFormat(dpy, xvi[i].visual); - if (format->type == PictTypeDirect && format->direct.alphaMask) - { - visual = xvi[i].visual; - depth = xvi[i].depth; - haveArgbVisual = true; - break; - } - } - - if (haveArgbVisual) - label = new ArgbLabel(visual, depth); - else -#endif - label = new QWidgetLabel(); -} - -KToolTipManager::~KToolTipManager() -{ - delete label; - delete currentItem; -} - -void KToolTipManager::showTip(const QPoint &pos, KToolTipItem *item) -{ - hideTip(); - label->showTip(pos, item); - currentItem = item; - m_tooltipPos = pos; -} - -void KToolTipManager::hideTip() -{ - label->hideTip(); - delete currentItem; - currentItem = 0; -} - -void KToolTipManager::initStyleOption(KStyleOptionToolTip *option) const -{ - option->direction = QApplication::layoutDirection(); - option->fontMetrics = QFontMetrics(QToolTip::font()); - option->activeCorner = KStyleOptionToolTip::TopLeftCorner; - option->palette = QToolTip::palette(); - option->font = QToolTip::font(); - option->rect = QRect(); - option->state = QStyle::State_None; - option->decorationSize = QSize(32, 32); -} - -bool KToolTipManager::haveAlphaChannel() const -{ -#ifdef Q_WS_X11 - // ### This is a synchronous call - ideally we'd use a selection - // watcher to avoid it. - return haveArgbVisual && - XGetSelectionOwner(QX11Info::display(), net_wm_cm_s0) != None; -#else - return false; -#endif -} - -void KToolTipManager::setDelegate(KToolTipDelegate *delegate) -{ - m_delegate = delegate; -} - -void KToolTipManager::update() -{ - if (currentItem == 0) - return; - label->showTip(m_tooltipPos, currentItem); -} - -KToolTipDelegate *KToolTipManager::delegate() const -{ - return m_delegate; -} - - - -// ---------------------------------------------------------------------------- - - - -namespace KToolTip -{ - void showText(const QPoint &pos, const QString &text, QWidget *widget, const QRect &rect) - { - Q_UNUSED(widget) - Q_UNUSED(rect) - KToolTipItem *item = new KToolTipItem(text); - KToolTipManager::instance()->showTip(pos, item); - } - - void showText(const QPoint &pos, const QString &text, QWidget *widget) - { - showText(pos, text, widget, QRect()); - } - - void showTip(const QPoint &pos, KToolTipItem *item) - { - KToolTipManager::instance()->showTip(pos, item); - } - - void hideTip() - { - KToolTipManager::instance()->hideTip(); - } - - void setToolTipDelegate(KToolTipDelegate *delegate) - { - KToolTipManager::instance()->setDelegate(delegate); - } -} - diff --git a/src/ktooltip.h b/src/ktooltip.h deleted file mode 100644 index d59f1bf17..000000000 --- a/src/ktooltip.h +++ /dev/null @@ -1,198 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Fredrik Höglund * - * * - * 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 of the License, 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. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#ifndef KTOOLTIP_H -#define KTOOLTIP_H - -#include -#include -#include -#include -#include -#include - -class QString; -class QIcon; -class QSize; -class QPainter; -class QRegion; - -class KToolTipItemPrivate; - -/** - * KToolTipItem contains the data to be displayed in a tooltip. - * - * Custom data can be stored as QVariants in the object by calling - * setData() with a custom item role, and retrieved and displayed - * by a tooltip delegate by calling data(). - * - * The default tooltip delegate uses Qt::DecorationRole and - * Qt::DisplayRole. - * - * To display the tooltip, call KToolTip::showTip() with a pointer - * to the KToolTipItem. - * - * You can reimplement the setData() and/or data() methods in this - * class to implement on-demand loading of data. - */ -class KToolTipItem -{ -public: - enum ItemType { DefaultType, UserType = 1000 }; - - /** - * Creates a KToolTipItem with @p text and no icon. - */ - explicit KToolTipItem(const QString &text, int type = DefaultType); - - /** - * Creates a KToolTipItem with an @p icon and @p text. - */ - KToolTipItem(const QIcon &icon, const QString &text, int type = DefaultType); - - /** - * Destroys the KToolTipItem. - */ - virtual ~KToolTipItem(); - - /** - * Returns the item type. - */ - int type() const; - - QString text() const; - QIcon icon() const; - - virtual QVariant data(int role) const; - virtual void setData(int role, const QVariant &data); - -private: - KToolTipItemPrivate * const d; -}; - - -class KStyleOptionToolTip -{ -public: - KStyleOptionToolTip(); - enum Corner { TopLeftCorner, TopRightCorner, BottomLeftCorner, BottomRightCorner, NoCorner }; - - Qt::LayoutDirection direction; - QFontMetrics fontMetrics; - QPalette palette; - QRect rect; - QStyle::State state; - QFont font; - QSize decorationSize; - Corner activeCorner; -}; - -/** - * KToolTipDelegate is responsible for providing the size hint and - * painting the tooltips. - */ -class KToolTipDelegate : public QObject -{ - Q_OBJECT -public: - KToolTipDelegate(); - virtual ~KToolTipDelegate(); - - virtual QSize sizeHint(const KStyleOptionToolTip *option, const KToolTipItem *item) const; - - /** - * If haveAlphaChannel() returns true, the paint device will be filled with - * Qt::transparent when this function is called, otherwise the content is - * undefined. - */ - virtual void paint(QPainter *painter, const KStyleOptionToolTip *option, - const KToolTipItem *item) const; - - /** - * Reimplement this function to specify the region of the tooltip - * that accepts input. Any mouse events that occur outside this - * region will be sent to the widget below the tooltip. - * - * The default implementation returns a region containing the - * bounding rect of the tooltip. - * - * This function will only be called if haveAlphaChannel() - * returns true. - */ - virtual QRegion inputShape(const KStyleOptionToolTip *option) const; - - /** - * Reimplement this function to specify a shape mask for the tooltip. - * - * The default implementation returns a region containing the - * bounding rect of the tooltip. - * - * This function will only be called if haveAlphaChannel() - * returns false. - */ - virtual QRegion shapeMask(const KStyleOptionToolTip *option) const; - -protected: - /** - * Returns true if the tooltip has an alpha channel, and false - * otherwise. - * - * Implementors should assume that this condition may change at - * any time during the runtime of the application, as compositing - * can be enabled or disabled in the window manager. - */ - bool haveAlphaChannel() const; - -#if 0 -private Q_SLOTS: - /** - * Schedules a repaint of the tooltip item. - * This slot can be connected to a timer to animate the tooltip. - */ - void update(const KToolTipItem *item); -#endif -}; - - -/** - * KToolTip provides customizable tooltips that can have animations as well as an alpha - * channel, allowing for dynamic transparency effects. - * - * ARGB tooltips work on X11 even when the application isn't using the ARGB visual. - */ -namespace KToolTip -{ - void showText(const QPoint &pos, const QString &text, QWidget *widget, const QRect &rect); - void showText(const QPoint &pos, const QString &text, QWidget *widget = 0); - - /** - * Shows the tip @p item at the global position indicated by @p pos. - * - * Ownership of the item is transferred to KToolTip. The item will be deleted - * automatically when it is hidden. - * - * The tip is shown immediately when this function is called. - */ - void showTip(const QPoint &pos, KToolTipItem *item); - void hideTip(); - - void setToolTipDelegate(KToolTipDelegate *delegate); -} - -#endif diff --git a/src/ktooltip_p.h b/src/ktooltip_p.h deleted file mode 100644 index 332df4854..000000000 --- a/src/ktooltip_p.h +++ /dev/null @@ -1,67 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Fredrik Höglund * - * * - * 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 of the License, 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. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#ifndef KTOOLTIP_P_H -#define KTOOLTIP_P_H - -class KAbstractToolTipLabel; -class KStyleOptionToolTip; -class KToolTipDelegate; - -class KToolTipManager -{ -public: - ~KToolTipManager(); - - static KToolTipManager *instance() { - if (!s_instance) - s_instance = new KToolTipManager(); - - return s_instance; - } - - void showTip(const QPoint &pos, KToolTipItem *item); - void hideTip(); - - void initStyleOption(KStyleOptionToolTip *option) const; - bool haveAlphaChannel() const; - - void setDelegate(KToolTipDelegate *delegate); - KToolTipDelegate *delegate() const; - - void update(); - -private: - KToolTipManager(); - - KAbstractToolTipLabel *label; - KToolTipItem *currentItem; - KToolTipDelegate *m_delegate; - - QPoint m_tooltipPos; - -#ifdef Q_WS_X11 - bool haveArgbVisual; - Atom net_wm_cm_s0; -#endif - - static KToolTipManager *s_instance; -}; - -#endif diff --git a/src/ktreeview.cpp b/src/ktreeview.cpp deleted file mode 100644 index 7c30fad33..000000000 --- a/src/ktreeview.cpp +++ /dev/null @@ -1,180 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by * - * Copyright (C) 2008 by * - * * - * 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 of the License, 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. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#include "ktreeview.h" -#include "ktreeview_p.h" - -#include - -#include -#include -#include -#include - -KTreeView::KTreeViewPrivate::KTreeViewPrivate(KTreeView *parent) : - parent(parent), - autoHorizontalScroll(false), - timeLine(0), - startScrollTimer(0) -{ - startScrollTimer = new QTimer(this); - startScrollTimer->setSingleShot(true); - startScrollTimer->setInterval(300); - connect(startScrollTimer, SIGNAL(timeout()), - this, SLOT(startScrolling())); - - timeLine = new QTimeLine(300, this); - connect(timeLine, SIGNAL(frameChanged(int)), - this, SLOT(updateVerticalScrollBar(int))); - - connect(parent->verticalScrollBar(), SIGNAL(rangeChanged(int, int)), - startScrollTimer, SLOT(start())); - connect(parent->verticalScrollBar(), SIGNAL(valueChanged(int)), - startScrollTimer, SLOT(start())); - connect(parent, SIGNAL(collapsed(const QModelIndex&)), - startScrollTimer, SLOT(start())); - connect(parent, SIGNAL(expanded(const QModelIndex&)), - startScrollTimer, SLOT(start())); -} - -void KTreeView::KTreeViewPrivate::startScrolling() -{ - QModelIndex index; - - const int viewportHeight = parent->viewport()->height(); - - // check whether there is a selected index which is partly visible - const QModelIndexList selectedIndexes = parent->selectionModel()->selectedIndexes(); - if (selectedIndexes.count() == 1) { - QModelIndex selectedIndex = selectedIndexes.first(); - const QRect rect = parent->visualRect(selectedIndex); - if ((rect.bottom() >= 0) && (rect.top() <= viewportHeight)) { - // the selected index is (at least partly) visible, use it as - // scroll target - index = selectedIndex; - } - } - - if (!index.isValid()) { - // no partly selected index is visible, determine the most left visual index - QModelIndex visibleIndex = parent->indexAt(QPoint(0, 0)); - if (!visibleIndex.isValid()) { - return; - } - - index = visibleIndex; - int minimum = parent->width(); - do { - const QRect rect = parent->visualRect(visibleIndex); - if (rect.top() > viewportHeight) { - // the current index and all successors are not visible anymore - break; - } - if (rect.left() < minimum) { - minimum = rect.left(); - index = visibleIndex; - } - visibleIndex = parent->indexBelow(visibleIndex); - } while (visibleIndex.isValid()); - } - - // start the horizontal scrolling to assure that the item indicated by 'index' gets fully visible - Q_ASSERT(index.isValid()); - const QRect rect = parent->visualRect(index); - - QScrollBar *scrollBar = parent->horizontalScrollBar(); - const int oldScrollBarPos = scrollBar->value(); - - const int itemRight = oldScrollBarPos + rect.left() + rect.width() - 1; - const int availableWidth = parent->viewport()->width(); - int scrollBarPos = itemRight - availableWidth; - const int scrollBarPosMax = oldScrollBarPos + rect.left() - parent->indentation(); - if (scrollBarPos > scrollBarPosMax) { - scrollBarPos = scrollBarPosMax; - } - - if (scrollBarPos != oldScrollBarPos) { - timeLine->setFrameRange(oldScrollBarPos, scrollBarPos); - timeLine->start(); - } -} - -void KTreeView::KTreeViewPrivate::updateVerticalScrollBar(int value) -{ - QScrollBar *scrollBar = parent->horizontalScrollBar(); - scrollBar->setValue(value); - startScrollTimer->stop(); -} - -// ************************************************ - -KTreeView::KTreeView(QWidget *parent) : - QTreeView(parent), - d(new KTreeViewPrivate(this)) -{ - if (KGlobalSettings::graphicEffectsLevel() >= KGlobalSettings::SimpleAnimationEffects) { - setAutoHorizontalScroll(true); - } -} - -KTreeView::~KTreeView() -{ -} - -void KTreeView::setAutoHorizontalScroll(bool value) -{ - d->autoHorizontalScroll = value; -} - -bool KTreeView::autoHorizontalScroll() const -{ - return d->autoHorizontalScroll; -} - -void KTreeView::setSelectionModel(QItemSelectionModel *selectionModel) -{ - QTreeView::setSelectionModel(selectionModel); - connect(selectionModel, - SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)), - d->startScrollTimer, SLOT(start())); -} - -void KTreeView::scrollTo(const QModelIndex& index, ScrollHint hint) -{ - if (d->autoHorizontalScroll) { - // assure that the value of the horizontal scrollbar stays on its current value, - // KTreeView will adjust the value manually - const int value = horizontalScrollBar()->value(); - QTreeView::scrollTo(index, hint); - horizontalScrollBar()->setValue(value); - } else { - QTreeView::scrollTo(index, hint); - } -} - -void KTreeView::hideEvent(QHideEvent *event) -{ - d->startScrollTimer->stop(); - d->timeLine->stop(); - QTreeView::hideEvent(event); -} - -#include "ktreeview.moc" -#include "ktreeview_p.moc" diff --git a/src/ktreeview.h b/src/ktreeview.h deleted file mode 100644 index 6bc6ea56a..000000000 --- a/src/ktreeview.h +++ /dev/null @@ -1,48 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by * - * Copyright (C) 2008 by * - * * - * 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 of the License, 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. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#ifndef KTREEVIEW_H -#define KTREEVIEW_H - -#include - -class KTreeView : public QTreeView -{ - Q_OBJECT - -public: - KTreeView(QWidget *parent = 0); - virtual ~KTreeView(); - - void setAutoHorizontalScroll(bool value); - bool autoHorizontalScroll() const; - - virtual void setSelectionModel(QItemSelectionModel *selectionModel); - virtual void scrollTo(const QModelIndex& index, ScrollHint hint = EnsureVisible); - -protected: - virtual void hideEvent(QHideEvent *event); - -private: - class KTreeViewPrivate; - KTreeViewPrivate *d; -}; - -#endif /* ifndef KTREEVIEW_H */ diff --git a/src/ktreeview_p.h b/src/ktreeview_p.h deleted file mode 100644 index 1cfa463cd..000000000 --- a/src/ktreeview_p.h +++ /dev/null @@ -1,49 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by * - * Copyright (C) 2008 by * - * * - * 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 of the License, 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. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#ifndef KTREEVIEW_P_H -#define KTREEVIEW_P_H - -#include - -#include "ktreeview.h" - -class QTimer; -class QTimeLine; - -class KTreeView::KTreeViewPrivate : public QObject -{ - Q_OBJECT - -public Q_SLOTS: - void startScrolling(); - void updateVerticalScrollBar(int value); - -public: - KTreeViewPrivate(KTreeView *parent); - KTreeView *parent; - void setScrollTowards( int scrollTowards ); - - bool autoHorizontalScroll; - QTimeLine *timeLine; - QTimer *startScrollTimer; -}; - -#endif /* ifndef KTREEVIEW_P_H */ diff --git a/src/metadatawidget.cpp b/src/metadatawidget.cpp deleted file mode 100644 index 218a6d1ce..000000000 --- a/src/metadatawidget.cpp +++ /dev/null @@ -1,281 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2007 by Sebastian Trueg * - * * - * 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 of the License, 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. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#include "metadatawidget.h" - -#include "commentwidget.h" - -#include - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#ifdef HAVE_NEPOMUK -#include "nepomukmassupdatejob.h" -#include -#include -#include -#include -#include -#include -#include "tagcloud/resourcetaggingwidget.h" -#endif - - -bool MetaDataWidget::metaDataAvailable() -{ -#ifdef HAVE_NEPOMUK - return !Nepomuk::ResourceManager::instance()->init(); -#else - return false; -#endif -} - - -class MetaDataWidget::Private -{ -public: -#ifdef HAVE_NEPOMUK - void loadComment(const QString& comment); - - CommentWidget* editComment; - KRatingWidget* ratingWidget; - Nepomuk::ResourceTaggingWidget* tagWidget; - - // shared data between the GUI-thread and - // the loader-thread (see LoadFilesThread): - QMutex mutex; - struct SharedData - { - int rating; - QString comment; - QList fileRes; - QMap files; - } sharedData; - - /** - * Loads the meta data of files and writes - * the result into a shared data pool that - * can be used by the widgets in the GUI thread. - */ - class LoadFilesThread : public QThread - { - public: - LoadFilesThread(SharedData* sharedData, QMutex* mutex); - void setFiles(const KUrl::List& urls); - virtual void run(); - - private: - SharedData* m_sharedData; - QMutex* m_mutex; - KUrl::List m_urls; - }; - - LoadFilesThread* loadFilesThread; -#endif -}; - -#ifdef HAVE_NEPOMUK -void MetaDataWidget::Private::loadComment(const QString& comment) -{ - editComment->setComment( comment ); -} - -MetaDataWidget::Private::LoadFilesThread::LoadFilesThread( - MetaDataWidget::Private::SharedData* sharedData, - QMutex* mutex) : - m_sharedData(sharedData), - m_mutex(mutex), - m_urls() -{ -} - -void MetaDataWidget::Private::LoadFilesThread::setFiles(const KUrl::List& urls) -{ - QMutexLocker locker( m_mutex ); - m_urls = urls; -} - -void MetaDataWidget::Private::LoadFilesThread::run() -{ - QMutexLocker locker( m_mutex ); - const KUrl::List urls = m_urls; - locker.unlock(); - - bool first = true; - QList fileRes; - QMap files; - unsigned int rating = 0; - QString comment; - Q_FOREACH( const KUrl &url, urls ) { - Nepomuk::Resource file( url, Soprano::Vocabulary::Xesam::File() ); - files.insert( url, file ); - fileRes.append( file ); - - if ( !first && rating != file.rating() ) { - rating = 0; // reset rating - } - else if ( first ) { - rating = file.rating(); - } - - if ( !first && comment != file.description() ) { - comment.clear(); - } - else if ( first ) { - comment = file.description(); - } - first = false; - } - - locker.relock(); - m_sharedData->rating = rating; - m_sharedData->comment = comment; - m_sharedData->fileRes = fileRes; - m_sharedData->files = files; -} -#endif - -MetaDataWidget::MetaDataWidget(QWidget* parent) : - QWidget(parent) -{ -#ifdef HAVE_NEPOMUK - d = new Private; - d->editComment = new CommentWidget(this); - d->editComment->setFocusPolicy(Qt::ClickFocus); - d->ratingWidget = new KRatingWidget(this); - d->ratingWidget->setAlignment( Qt::AlignCenter ); - d->tagWidget = new Nepomuk::ResourceTaggingWidget(this); - connect(d->ratingWidget, SIGNAL(ratingChanged(unsigned int)), this, SLOT(slotRatingChanged(unsigned int))); - connect(d->editComment, SIGNAL(commentChanged(const QString&)), this, SLOT(slotCommentChanged(const QString&))); - connect( d->tagWidget, SIGNAL( tagClicked( const Nepomuk::Tag& ) ), this, SLOT( slotTagClicked( const Nepomuk::Tag& ) ) ); - - d->sharedData.rating = 0; - d->loadFilesThread = new Private::LoadFilesThread(&d->sharedData, &d->mutex); - connect(d->loadFilesThread, SIGNAL(finished()), this, SLOT(slotLoadingFinished())); - - QVBoxLayout* lay = new QVBoxLayout(this); - lay->setMargin(0); - lay->addWidget(d->ratingWidget); - lay->addWidget(d->editComment); - lay->addWidget( d->tagWidget ); -#else - d = 0; -#endif -} - - -MetaDataWidget::~MetaDataWidget() -{ -#ifdef HAVE_NEPOMUK - delete d->loadFilesThread; -#endif - delete d; -} - - -void MetaDataWidget::setFile(const KUrl& url) -{ - kDebug() << url; - KUrl::List urls; - urls.append( url ); - setFiles( urls ); -} - -void MetaDataWidget::setFiles(const KUrl::List& urls) -{ -#ifdef HAVE_NEPOMUK - d->loadFilesThread->setFiles( urls ); - d->loadFilesThread->start(); -#else - Q_UNUSED( urls ); -#endif -} - - -void MetaDataWidget::slotCommentChanged( const QString& s ) -{ -#ifdef HAVE_NEPOMUK - QMutexLocker locker( &d->mutex ); - Nepomuk::MassUpdateJob* job = Nepomuk::MassUpdateJob::commentResources( d->sharedData.files.values(), s ); - connect( job, SIGNAL( result( KJob* ) ), - this, SLOT( metadataUpdateDone() ) ); - setEnabled( false ); // no updates during execution - job->start(); -#else - Q_UNUSED( s ); -#endif -} - - -void MetaDataWidget::slotRatingChanged(unsigned int rating) -{ -#ifdef HAVE_NEPOMUK - QMutexLocker locker( &d->mutex ); - Nepomuk::MassUpdateJob* job = Nepomuk::MassUpdateJob::rateResources( d->sharedData.files.values(), rating ); - connect( job, SIGNAL( result( KJob* ) ), - this, SLOT( metadataUpdateDone() ) ); - setEnabled( false ); // no updates during execution - job->start(); -#else - Q_UNUSED( rating ); -#endif -} - - -void MetaDataWidget::metadataUpdateDone() -{ - setEnabled( true ); -} - - -bool MetaDataWidget::eventFilter(QObject* obj, QEvent* event) -{ - return QWidget::eventFilter(obj, event); -} - - -void MetaDataWidget::slotTagClicked( const Nepomuk::Tag& tag ) -{ - Q_UNUSED( tag ); -#ifdef HAVE_NEPOMUK - d->tagWidget->showTagPopup( QCursor::pos() ); -#endif -} - -void MetaDataWidget::slotLoadingFinished() -{ -#ifdef HAVE_NEPOMUK - QMutexLocker locker( &d->mutex ); - d->ratingWidget->setRating( d->sharedData.rating ); - d->loadComment( d->sharedData.comment ); - d->tagWidget->setResources( d->sharedData.fileRes ); -#endif -} - -#include "metadatawidget.moc" diff --git a/src/metadatawidget.h b/src/metadatawidget.h deleted file mode 100644 index 881c23c42..000000000 --- a/src/metadatawidget.h +++ /dev/null @@ -1,72 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2007 by Sebastian Trueg * - * * - * 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 of the License, 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. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#ifndef METADATA_WIDGET_H -#define METADATA_WIDGET_H - -#include - -#include - -namespace Nepomuk { - class Tag; -} - -class MetaDataWidget : public QWidget -{ - Q_OBJECT - -public: - MetaDataWidget(QWidget* parent = 0); - virtual ~MetaDataWidget(); - - /** - * \return true if the KMetaData system could be found and initialized. - * false if KMetaData was not available at compile time or if it has not - * been initialized properly. - */ - static bool metaDataAvailable(); - -public Q_SLOTS: - void setFile(const KUrl& url); - void setFiles(const KUrl::List& urls); - -signals: - /** - * This signal gets emitted if the metadata for the set file was changed on the - * outside. NOT IMPLEMENTED YET. - */ - void metaDataChanged(); - -private Q_SLOTS: - void slotCommentChanged(const QString&); - void slotRatingChanged(unsigned int rating); - void metadataUpdateDone(); - void slotTagClicked( const Nepomuk::Tag& ); - void slotLoadingFinished(); - -protected: - bool eventFilter(QObject* obj, QEvent* event); - -private: - class Private; - Private* d; -}; - -#endif diff --git a/src/metatextlabel.cpp b/src/metatextlabel.cpp deleted file mode 100644 index 66f12db90..000000000 --- a/src/metatextlabel.cpp +++ /dev/null @@ -1,135 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Peter Penz * - * * - * 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 of the License, 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. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#include "metatextlabel.h" - -#include -#include - -#include -#include -#include -#include - -MetaTextLabel::MetaTextLabel(QWidget* parent) : - QWidget(parent), - m_minimumHeight(0), - m_metaInfos() -{ - setFont(KGlobalSettings::smallestReadableFont()); -} - -MetaTextLabel::~MetaTextLabel() -{ -} - -void MetaTextLabel::clear() -{ - m_minimumHeight = 0; - m_metaInfos.clear(); - update(); -} - -void MetaTextLabel::add(const QString& labelText, const QString& infoText) -{ - MetaInfo metaInfo; - metaInfo.label = labelText; - metaInfo.info = infoText; - - m_metaInfos.append(metaInfo); - - m_minimumHeight += requiredHeight(metaInfo); - setMinimumHeight(m_minimumHeight); - - update(); -} - -void MetaTextLabel::paintEvent(QPaintEvent* event) -{ - QWidget::paintEvent(event); - - QPainter painter(this); - - const QColor infoColor = palette().color(QPalette::Foreground); - QColor labelColor = infoColor; - labelColor.setAlpha(128); - - int y = 0; - const int infoWidth = width() / 2; - const int labelWidth = infoWidth - 2 * Spacing; - const int infoX = infoWidth; - const int maxHeight = fontMetrics().height() * 5; - - QRect boundingRect; - foreach (const MetaInfo& metaInfo, m_metaInfos) { - // draw label (e. g. "Date:") - painter.setPen(labelColor); - painter.drawText(0, y, labelWidth, maxHeight, - Qt::AlignTop | Qt::AlignRight | Qt::TextWordWrap, - metaInfo.label); - - // draw information (e. g. "2008-11-09 20:12") - painter.setPen(infoColor); - painter.drawText(infoX, y, infoWidth, maxHeight, - Qt::AlignTop | Qt::AlignLeft | Qt::TextWordWrap, - metaInfo.info, - &boundingRect); - - y += boundingRect.height() + Spacing; - } -} - -void MetaTextLabel::resizeEvent(QResizeEvent* event) -{ - QWidget::resizeEvent(event); - - m_minimumHeight = 0; - foreach (const MetaInfo& metaInfo, m_metaInfos) { - m_minimumHeight += requiredHeight(metaInfo); - } - setMinimumHeight(m_minimumHeight); -} - -int MetaTextLabel::requiredHeight(const MetaInfo& metaInfo) const -{ - QTextOption textOption; - textOption.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere); - - qreal height = 0; - const int leading = fontMetrics().leading(); - const int availableWidth = width() / 2; - - QTextLayout textLayout(metaInfo.info); - textLayout.setFont(font()); - textLayout.setTextOption(textOption); - - textLayout.beginLayout(); - QTextLine line = textLayout.createLine(); - while (line.isValid()) { - line.setLineWidth(availableWidth); - height += leading; - height += line.height(); - line = textLayout.createLine(); - } - textLayout.endLayout(); - - return static_cast(height) + Spacing; -} - -#include "metatextlabel.moc" diff --git a/src/metatextlabel.h b/src/metatextlabel.h deleted file mode 100644 index f70d29d8e..000000000 --- a/src/metatextlabel.h +++ /dev/null @@ -1,64 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Peter Penz * - * * - * 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 of the License, 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. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#ifndef METATEXTLABEL_H -#define METATEXTLABEL_H - -#include - -/** - * @brief Displays general meta in several lines. - * - * Each line contains a label and the meta information. - */ -class MetaTextLabel : public QWidget -{ - Q_OBJECT - -public: - explicit MetaTextLabel(QWidget* parent = 0); - virtual ~MetaTextLabel(); - - void clear(); - void add(const QString& labelText, const QString& infoText); - -protected: - virtual void paintEvent(QPaintEvent* event); - virtual void resizeEvent(QResizeEvent* event); - -private: - enum { Spacing = 2 }; - - struct MetaInfo - { - QString label; - QString info; - }; - - int m_minimumHeight; - QList m_metaInfos; - - /** - * Returns the required height in pixels for \a metaInfo to - * fit into the available width of the widget. - */ - int requiredHeight(const MetaInfo& metaInfo) const; -}; - -#endif diff --git a/src/nepomukmassupdatejob.cpp b/src/nepomukmassupdatejob.cpp deleted file mode 100644 index 5c883fd4b..000000000 --- a/src/nepomukmassupdatejob.cpp +++ /dev/null @@ -1,163 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Sebastian Trueg * - * * - * 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 of the License, 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. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#include "nepomukmassupdatejob.h" - -#include -#include - -#include -#include - - -Nepomuk::MassUpdateJob::MassUpdateJob( QObject* parent ) - : KJob( parent ), - m_index( -1 ) -{ - kDebug(); - setCapabilities( Killable|Suspendable ); - connect( &m_processTimer, SIGNAL( timeout() ), - this, SLOT( slotNext() ) ); -} - - -Nepomuk::MassUpdateJob::~MassUpdateJob() -{ - kDebug(); -} - - -void Nepomuk::MassUpdateJob::setFiles( const KUrl::List& urls ) -{ - m_resources.clear(); - foreach( const KUrl &url, urls ) { - m_resources.append( Resource( url ) ); - } - setTotalAmount( KJob::Files, m_resources.count() ); -} - - -void Nepomuk::MassUpdateJob::setResources( const QList& rl ) -{ - m_resources = rl; - setTotalAmount( KJob::Files, m_resources.count() ); -} - - -void Nepomuk::MassUpdateJob::setProperties( const QList >& props ) -{ - m_properties = props; -} - - -void Nepomuk::MassUpdateJob::start() -{ - if ( m_index < 0 ) { - kDebug(); - emit description( this, - i18nc("@info:progress", "Changing annotations") ); - m_index = 0; - m_processTimer.start(); - } - else { - kDebug() << "Job has already been started"; - } -} - - -bool Nepomuk::MassUpdateJob::doKill() -{ - if ( m_index > 0 ) { - m_processTimer.stop(); - m_index = -1; - return true; - } - else { - return false; - } -} - - -bool Nepomuk::MassUpdateJob::doSuspend() -{ - m_processTimer.stop(); - return true; -} - - -bool Nepomuk::MassUpdateJob::doResume() -{ - if ( m_index > 0 ) { - m_processTimer.start(); - return true; - } - else { - return false; - } -} - - -void Nepomuk::MassUpdateJob::slotNext() -{ - if ( !isSuspended() ) { - if ( m_index < m_resources.count() ) { - Nepomuk::Resource& res = m_resources[m_index]; - for ( int i = 0; i < m_properties.count(); ++i ) { - res.setProperty( m_properties[i].first, m_properties[i].second ); - } - ++m_index; - setProcessedAmount( KJob::Files, m_index ); - } - else if ( m_index >= m_resources.count() ) { - kDebug() << "done"; - m_index = -1; - m_processTimer.stop(); - emitResult(); - } - } -} - - -Nepomuk::MassUpdateJob* Nepomuk::MassUpdateJob::tagResources( const QList& rl, const QList& tags ) -{ - Nepomuk::MassUpdateJob* job = new Nepomuk::MassUpdateJob(); - job->setResources( rl ); - job->setProperties( QList >() << qMakePair( QUrl( Nepomuk::Resource::tagUri() ), Nepomuk::Variant( convertResourceList( tags ) ) ) ); - return job; -} - - -Nepomuk::MassUpdateJob* Nepomuk::MassUpdateJob::rateResources( const QList& rl, int rating ) -{ - Nepomuk::MassUpdateJob* job = new Nepomuk::MassUpdateJob(); - job->setResources( rl ); - job->setProperties( QList >() << qMakePair( QUrl( Nepomuk::Resource::ratingUri() ), Nepomuk::Variant( rating ) ) ); - return job; -} - - -Nepomuk::MassUpdateJob* Nepomuk::MassUpdateJob::commentResources( const QList& rl, const QString& comment ) -{ - Nepomuk::MassUpdateJob* job = new Nepomuk::MassUpdateJob(); - job->setResources( rl ); - job->setProperties( QList >() << qMakePair( QUrl( Nepomuk::Resource::descriptionUri() ), Nepomuk::Variant( comment ) ) ); - return job; -} - -#include "nepomukmassupdatejob.moc" diff --git a/src/nepomukmassupdatejob.h b/src/nepomukmassupdatejob.h deleted file mode 100644 index a19fa5ff9..000000000 --- a/src/nepomukmassupdatejob.h +++ /dev/null @@ -1,85 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Sebastian Trueg * - * * - * 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 of the License, 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. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#ifndef _NEPOMUK_MASS_UPDATE_JOB_H_ -#define _NEPOMUK_MASS_UPDATE_JOB_H_ - -#include -#include - -#include -#include -#include - -#include -#include - - -namespace Nepomuk { - class MassUpdateJob : public KJob - { - Q_OBJECT - - public: - MassUpdateJob( QObject* parent = 0 ); - ~MassUpdateJob(); - - /** - * Set a list of files to change - * This has the same effect as using setResources - * with a list of manually created resources. - */ - void setFiles( const KUrl::List& urls ); - - /** - * Set a list of resources to change. - */ - void setResources( const QList& ); - - /** - * Set the properties to change in the mass update. - */ - void setProperties( const QList >& props ); - - /** - * Actually start the job. - */ - void start(); - - static MassUpdateJob* tagResources( const QList&, const QList& tags ); - static MassUpdateJob* commentResources( const QList&, const QString& comment ); - static MassUpdateJob* rateResources( const QList&, int rating ); - - protected: - bool doKill(); - bool doSuspend(); - bool doResume(); - - private Q_SLOTS: - void slotNext(); - - private: - QList m_resources; - QList > m_properties; - int m_index; - QTimer m_processTimer; - }; -} - -#endif diff --git a/src/panels/folders/dolphin_folderspanelsettings.kcfg b/src/panels/folders/dolphin_folderspanelsettings.kcfg new file mode 100644 index 000000000..816d783c8 --- /dev/null +++ b/src/panels/folders/dolphin_folderspanelsettings.kcfg @@ -0,0 +1,11 @@ + + + + + + + + false + + + diff --git a/src/panels/folders/dolphin_folderspanelsettings.kcfgc b/src/panels/folders/dolphin_folderspanelsettings.kcfgc new file mode 100644 index 000000000..f73e8807d --- /dev/null +++ b/src/panels/folders/dolphin_folderspanelsettings.kcfgc @@ -0,0 +1,4 @@ +File=dolphin_folderspanelsettings.kcfg +ClassName=FoldersPanelSettings +Singleton=true +Mutators=true diff --git a/src/panels/folders/ktreeview.cpp b/src/panels/folders/ktreeview.cpp new file mode 100644 index 000000000..7c30fad33 --- /dev/null +++ b/src/panels/folders/ktreeview.cpp @@ -0,0 +1,180 @@ +/*************************************************************************** + * Copyright (C) 2008 by * + * Copyright (C) 2008 by * + * * + * 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 of the License, 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. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#include "ktreeview.h" +#include "ktreeview_p.h" + +#include + +#include +#include +#include +#include + +KTreeView::KTreeViewPrivate::KTreeViewPrivate(KTreeView *parent) : + parent(parent), + autoHorizontalScroll(false), + timeLine(0), + startScrollTimer(0) +{ + startScrollTimer = new QTimer(this); + startScrollTimer->setSingleShot(true); + startScrollTimer->setInterval(300); + connect(startScrollTimer, SIGNAL(timeout()), + this, SLOT(startScrolling())); + + timeLine = new QTimeLine(300, this); + connect(timeLine, SIGNAL(frameChanged(int)), + this, SLOT(updateVerticalScrollBar(int))); + + connect(parent->verticalScrollBar(), SIGNAL(rangeChanged(int, int)), + startScrollTimer, SLOT(start())); + connect(parent->verticalScrollBar(), SIGNAL(valueChanged(int)), + startScrollTimer, SLOT(start())); + connect(parent, SIGNAL(collapsed(const QModelIndex&)), + startScrollTimer, SLOT(start())); + connect(parent, SIGNAL(expanded(const QModelIndex&)), + startScrollTimer, SLOT(start())); +} + +void KTreeView::KTreeViewPrivate::startScrolling() +{ + QModelIndex index; + + const int viewportHeight = parent->viewport()->height(); + + // check whether there is a selected index which is partly visible + const QModelIndexList selectedIndexes = parent->selectionModel()->selectedIndexes(); + if (selectedIndexes.count() == 1) { + QModelIndex selectedIndex = selectedIndexes.first(); + const QRect rect = parent->visualRect(selectedIndex); + if ((rect.bottom() >= 0) && (rect.top() <= viewportHeight)) { + // the selected index is (at least partly) visible, use it as + // scroll target + index = selectedIndex; + } + } + + if (!index.isValid()) { + // no partly selected index is visible, determine the most left visual index + QModelIndex visibleIndex = parent->indexAt(QPoint(0, 0)); + if (!visibleIndex.isValid()) { + return; + } + + index = visibleIndex; + int minimum = parent->width(); + do { + const QRect rect = parent->visualRect(visibleIndex); + if (rect.top() > viewportHeight) { + // the current index and all successors are not visible anymore + break; + } + if (rect.left() < minimum) { + minimum = rect.left(); + index = visibleIndex; + } + visibleIndex = parent->indexBelow(visibleIndex); + } while (visibleIndex.isValid()); + } + + // start the horizontal scrolling to assure that the item indicated by 'index' gets fully visible + Q_ASSERT(index.isValid()); + const QRect rect = parent->visualRect(index); + + QScrollBar *scrollBar = parent->horizontalScrollBar(); + const int oldScrollBarPos = scrollBar->value(); + + const int itemRight = oldScrollBarPos + rect.left() + rect.width() - 1; + const int availableWidth = parent->viewport()->width(); + int scrollBarPos = itemRight - availableWidth; + const int scrollBarPosMax = oldScrollBarPos + rect.left() - parent->indentation(); + if (scrollBarPos > scrollBarPosMax) { + scrollBarPos = scrollBarPosMax; + } + + if (scrollBarPos != oldScrollBarPos) { + timeLine->setFrameRange(oldScrollBarPos, scrollBarPos); + timeLine->start(); + } +} + +void KTreeView::KTreeViewPrivate::updateVerticalScrollBar(int value) +{ + QScrollBar *scrollBar = parent->horizontalScrollBar(); + scrollBar->setValue(value); + startScrollTimer->stop(); +} + +// ************************************************ + +KTreeView::KTreeView(QWidget *parent) : + QTreeView(parent), + d(new KTreeViewPrivate(this)) +{ + if (KGlobalSettings::graphicEffectsLevel() >= KGlobalSettings::SimpleAnimationEffects) { + setAutoHorizontalScroll(true); + } +} + +KTreeView::~KTreeView() +{ +} + +void KTreeView::setAutoHorizontalScroll(bool value) +{ + d->autoHorizontalScroll = value; +} + +bool KTreeView::autoHorizontalScroll() const +{ + return d->autoHorizontalScroll; +} + +void KTreeView::setSelectionModel(QItemSelectionModel *selectionModel) +{ + QTreeView::setSelectionModel(selectionModel); + connect(selectionModel, + SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)), + d->startScrollTimer, SLOT(start())); +} + +void KTreeView::scrollTo(const QModelIndex& index, ScrollHint hint) +{ + if (d->autoHorizontalScroll) { + // assure that the value of the horizontal scrollbar stays on its current value, + // KTreeView will adjust the value manually + const int value = horizontalScrollBar()->value(); + QTreeView::scrollTo(index, hint); + horizontalScrollBar()->setValue(value); + } else { + QTreeView::scrollTo(index, hint); + } +} + +void KTreeView::hideEvent(QHideEvent *event) +{ + d->startScrollTimer->stop(); + d->timeLine->stop(); + QTreeView::hideEvent(event); +} + +#include "ktreeview.moc" +#include "ktreeview_p.moc" diff --git a/src/panels/folders/ktreeview.h b/src/panels/folders/ktreeview.h new file mode 100644 index 000000000..6bc6ea56a --- /dev/null +++ b/src/panels/folders/ktreeview.h @@ -0,0 +1,48 @@ +/*************************************************************************** + * Copyright (C) 2008 by * + * Copyright (C) 2008 by * + * * + * 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 of the License, 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. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#ifndef KTREEVIEW_H +#define KTREEVIEW_H + +#include + +class KTreeView : public QTreeView +{ + Q_OBJECT + +public: + KTreeView(QWidget *parent = 0); + virtual ~KTreeView(); + + void setAutoHorizontalScroll(bool value); + bool autoHorizontalScroll() const; + + virtual void setSelectionModel(QItemSelectionModel *selectionModel); + virtual void scrollTo(const QModelIndex& index, ScrollHint hint = EnsureVisible); + +protected: + virtual void hideEvent(QHideEvent *event); + +private: + class KTreeViewPrivate; + KTreeViewPrivate *d; +}; + +#endif /* ifndef KTREEVIEW_H */ diff --git a/src/panels/folders/ktreeview_p.h b/src/panels/folders/ktreeview_p.h new file mode 100644 index 000000000..1cfa463cd --- /dev/null +++ b/src/panels/folders/ktreeview_p.h @@ -0,0 +1,49 @@ +/*************************************************************************** + * Copyright (C) 2008 by * + * Copyright (C) 2008 by * + * * + * 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 of the License, 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. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#ifndef KTREEVIEW_P_H +#define KTREEVIEW_P_H + +#include + +#include "ktreeview.h" + +class QTimer; +class QTimeLine; + +class KTreeView::KTreeViewPrivate : public QObject +{ + Q_OBJECT + +public Q_SLOTS: + void startScrolling(); + void updateVerticalScrollBar(int value); + +public: + KTreeViewPrivate(KTreeView *parent); + KTreeView *parent; + void setScrollTowards( int scrollTowards ); + + bool autoHorizontalScroll; + QTimeLine *timeLine; + QTimer *startScrollTimer; +}; + +#endif /* ifndef KTREEVIEW_P_H */ diff --git a/src/panels/folders/sidebartreeview.cpp b/src/panels/folders/sidebartreeview.cpp new file mode 100644 index 000000000..a876ee6c3 --- /dev/null +++ b/src/panels/folders/sidebartreeview.cpp @@ -0,0 +1,147 @@ +/*************************************************************************** + * Copyright (C) 2006 by Peter Penz * + * * + * 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 of the License, 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. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#include "sidebartreeview.h" + +#include "dolphincontroller.h" +#include "dolphinmodel.h" +#include "draganddrophelper.h" + +#include +#include +#include +#include +#include + +SidebarTreeView::SidebarTreeView(QWidget* parent) : + KTreeView(parent) +{ + setAcceptDrops(true); + setUniformRowHeights(true); + setSelectionMode(QAbstractItemView::SingleSelection); + setEditTriggers(QAbstractItemView::NoEditTriggers); + setSortingEnabled(true); + setFrameStyle(QFrame::NoFrame); + setDragDropMode(QAbstractItemView::DragDrop); + setDropIndicatorShown(false); + + setVerticalScrollMode(QListView::ScrollPerPixel); + setHorizontalScrollMode(QListView::ScrollPerPixel); + + viewport()->setAttribute(Qt::WA_Hover); + + // make the background transparent and apply the window-text color + // to the text color, so that enough contrast is given for all color + // schemes + QPalette p = palette(); + p.setColor(QPalette::Active, QPalette::Text, p.color(QPalette::Active, QPalette::WindowText)); + p.setColor(QPalette::Inactive, QPalette::Text, p.color(QPalette::Inactive, QPalette::WindowText)); + p.setColor(QPalette::Disabled, QPalette::Text, p.color(QPalette::Disabled, QPalette::WindowText)); + setPalette(p); + viewport()->setAutoFillBackground(false); + + KFileItemDelegate* delegate = new KFileItemDelegate(this); + setItemDelegate(delegate); +} + +SidebarTreeView::~SidebarTreeView() +{ +} + +bool SidebarTreeView::event(QEvent* event) +{ + switch (event->type()) { + case QEvent::Polish: + // hide all columns except of the 'Name' column + hideColumn(DolphinModel::Size); + hideColumn(DolphinModel::ModifiedTime); + hideColumn(DolphinModel::Permissions); + hideColumn(DolphinModel::Owner); + hideColumn(DolphinModel::Group); + hideColumn(DolphinModel::Type); + hideColumn(DolphinModel::Rating); + hideColumn(DolphinModel::Tags); + header()->hide(); + break; + + case QEvent::Show: + // TODO: The opening/closing animation of subtrees flickers in combination with the + // sidebar when using the Oxygen style. As workaround the animation is turned off: + setAnimated(false); + break; + + case QEvent::UpdateRequest: + // a wheel movement will scroll 1 item + if (model()->rowCount() > 0) { + verticalScrollBar()->setSingleStep(sizeHintForRow(0) / 3); + } + break; + + default: + break; + } + + return KTreeView::event(event); +} + +void SidebarTreeView::startDrag(Qt::DropActions supportedActions) +{ + DragAndDropHelper::instance().startDrag(this, supportedActions); +} + +void SidebarTreeView::dragEnterEvent(QDragEnterEvent* event) +{ + KTreeView::dragEnterEvent(event); + if (event->mimeData()->hasUrls()) { + event->acceptProposedAction(); + } +} + +void SidebarTreeView::dragLeaveEvent(QDragLeaveEvent* event) +{ + KTreeView::dragLeaveEvent(event); + setDirtyRegion(m_dropRect); +} + +void SidebarTreeView::dragMoveEvent(QDragMoveEvent* event) +{ + KTreeView::dragMoveEvent(event); + + // TODO: remove this code when the issue #160611 is solved in Qt 4.4 + const QModelIndex index = indexAt(event->pos()); + setDirtyRegion(m_dropRect); + m_dropRect = visualRect(index); + setDirtyRegion(m_dropRect); + + if (event->mimeData()->hasUrls()) { + // accept url drops, independently from the destination item + event->acceptProposedAction(); + } +} + +void SidebarTreeView::dropEvent(QDropEvent* event) +{ + const QModelIndex index = indexAt(event->pos()); + if (index.isValid()) { + emit urlsDropped(index, event); + } + KTreeView::dropEvent(event); +} + +#include "sidebartreeview.moc" diff --git a/src/panels/folders/sidebartreeview.h b/src/panels/folders/sidebartreeview.h new file mode 100644 index 000000000..a5e8b63ce --- /dev/null +++ b/src/panels/folders/sidebartreeview.h @@ -0,0 +1,58 @@ +/*************************************************************************** + * Copyright (C) 2006 by Peter Penz * + * * + * 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 of the License, 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. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#ifndef SIDEBARTREEVIEW_H +#define SIDEBARTREEVIEW_H + +#include +#include + +/** + * @brief Tree view widget which is used for the sidebar panel. + * + * @see TreeViewSidebarPage + */ +class SidebarTreeView : public KTreeView +{ + Q_OBJECT + +public: + explicit SidebarTreeView(QWidget* parent = 0); + virtual ~SidebarTreeView(); + +signals: + /** + * Is emitted if the URL have been dropped to + * the index \a index. + */ + void urlsDropped(const QModelIndex& index, QDropEvent* event); + +protected: + virtual bool event(QEvent* event); + virtual void startDrag(Qt::DropActions supportedActions); + virtual void dragEnterEvent(QDragEnterEvent* event); + virtual void dragLeaveEvent(QDragLeaveEvent* event); + virtual void dragMoveEvent(QDragMoveEvent* event); + virtual void dropEvent(QDropEvent* event); + +private: + QRect m_dropRect; +}; + +#endif diff --git a/src/panels/folders/treeviewcontextmenu.cpp b/src/panels/folders/treeviewcontextmenu.cpp new file mode 100644 index 000000000..9e8638002 --- /dev/null +++ b/src/panels/folders/treeviewcontextmenu.cpp @@ -0,0 +1,194 @@ +/*************************************************************************** + * Copyright (C) 2006 by Peter Penz (peter.penz@gmx.at) and * + * Cvetoslav Ludmiloff * + * * + * 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 of the License, 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. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#include "treeviewcontextmenu.h" + +#include "dolphin_folderspanelsettings.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "treeviewsidebarpage.h" + +#include +#include + +TreeViewContextMenu::TreeViewContextMenu(TreeViewSidebarPage* parent, + const KFileItem& fileInfo) : + QObject(parent), + m_parent(parent), + m_fileInfo(fileInfo) +{ +} + +TreeViewContextMenu::~TreeViewContextMenu() +{ +} + +void TreeViewContextMenu::open() +{ + KMenu* popup = new KMenu(m_parent); + + if (!m_fileInfo.isNull()) { + KonqFileItemCapabilities capabilities(KFileItemList() << m_fileInfo); + + // insert 'Cut', 'Copy' and 'Paste' + QAction* cutAction = new QAction(KIcon("edit-cut"), i18nc("@action:inmenu", "Cut"), this); + cutAction->setEnabled(capabilities.supportsMoving()); + connect(cutAction, SIGNAL(triggered()), this, SLOT(cut())); + + QAction* copyAction = new QAction(KIcon("edit-copy"), i18nc("@action:inmenu", "Copy"), this); + connect(copyAction, SIGNAL(triggered()), this, SLOT(copy())); + + QAction* pasteAction = new QAction(KIcon("edit-paste"), i18nc("@action:inmenu", "Paste"), this); + const QMimeData* mimeData = QApplication::clipboard()->mimeData(); + const KUrl::List pasteData = KUrl::List::fromMimeData(mimeData); + connect(pasteAction, SIGNAL(triggered()), this, SLOT(paste())); + pasteAction->setEnabled(!pasteData.isEmpty() && capabilities.supportsWriting()); + + popup->addAction(cutAction); + popup->addAction(copyAction); + popup->addAction(pasteAction); + popup->addSeparator(); + + // insert 'Rename' + QAction* renameAction = new QAction(i18nc("@action:inmenu", "Rename..."), this); + renameAction->setEnabled(capabilities.supportsMoving()); + connect(renameAction, SIGNAL(triggered()), this, SLOT(rename())); + popup->addAction(renameAction); + + // insert 'Move to Trash' and (optionally) 'Delete' + KSharedConfig::Ptr globalConfig = KSharedConfig::openConfig("kdeglobals", KConfig::IncludeGlobals); + KConfigGroup configGroup(globalConfig, "KDE"); + bool showDeleteCommand = configGroup.readEntry("ShowDeleteCommand", false); + + const KUrl& url = m_fileInfo.url(); + if (url.isLocalFile()) { + QAction* moveToTrashAction = new QAction(KIcon("user-trash"), + i18nc("@action:inmenu", "Move To Trash"), this); + const bool enableMoveToTrash = capabilities.isLocal() && capabilities.supportsMoving(); + moveToTrashAction->setEnabled(enableMoveToTrash); + connect(moveToTrashAction, SIGNAL(triggered()), this, SLOT(moveToTrash())); + popup->addAction(moveToTrashAction); + } else { + showDeleteCommand = true; + } + + if (showDeleteCommand) { + QAction* deleteAction = new QAction(KIcon("edit-delete"), i18nc("@action:inmenu", "Delete"), this); + deleteAction->setEnabled(capabilities.supportsDeleting()); + connect(deleteAction, SIGNAL(triggered()), this, SLOT(deleteItem())); + popup->addAction(deleteAction); + } + + popup->addSeparator(); + + // insert 'Properties' entry + QAction* propertiesAction = new QAction(i18nc("@action:inmenu", "Properties"), this); + connect(propertiesAction, SIGNAL(triggered()), this, SLOT(showProperties())); + popup->addAction(propertiesAction); + + popup->addSeparator(); + } + + QAction* showHiddenFilesAction = new QAction(i18nc("@action:inmenu", "Show Hidden Files"), this); + showHiddenFilesAction->setCheckable(true); + showHiddenFilesAction->setChecked(FoldersPanelSettings::showHiddenFiles()); + popup->addAction(showHiddenFilesAction); + + connect(showHiddenFilesAction, SIGNAL(toggled(bool)), this, SLOT(setShowHiddenFiles(bool))); + + popup->exec(QCursor::pos()); + popup->deleteLater(); +} + +void TreeViewContextMenu::populateMimeData(QMimeData* mimeData, bool cut) +{ + KUrl::List kdeUrls; + kdeUrls.append(m_fileInfo.url()); + KUrl::List mostLocalUrls; + bool dummy; + mostLocalUrls.append(m_fileInfo.mostLocalUrl(dummy)); + KonqMimeData::populateMimeData(mimeData, kdeUrls, mostLocalUrls, cut); +} + +void TreeViewContextMenu::cut() +{ + QMimeData* mimeData = new QMimeData(); + populateMimeData(mimeData, true); + QApplication::clipboard()->setMimeData(mimeData); +} + +void TreeViewContextMenu::copy() +{ + QMimeData* mimeData = new QMimeData(); + populateMimeData(mimeData, false); + QApplication::clipboard()->setMimeData(mimeData); +} + +void TreeViewContextMenu::paste() +{ + QClipboard* clipboard = QApplication::clipboard(); + const QMimeData* mimeData = clipboard->mimeData(); + + const KUrl::List source = KUrl::List::fromMimeData(mimeData); + const KUrl& dest = m_fileInfo.url(); + if (KonqMimeData::decodeIsCutSelection(mimeData)) { + KonqOperations::copy(m_parent, KonqOperations::MOVE, source, dest); + clipboard->clear(); + } else { + KonqOperations::copy(m_parent, KonqOperations::COPY, source, dest); + } +} + +void TreeViewContextMenu::rename() +{ + m_parent->rename(m_fileInfo); +} + +void TreeViewContextMenu::moveToTrash() +{ + KonqOperations::del(m_parent, KonqOperations::TRASH, m_fileInfo.url()); +} + +void TreeViewContextMenu::deleteItem() +{ + KonqOperations::del(m_parent, KonqOperations::DEL, m_fileInfo.url()); +} + +void TreeViewContextMenu::showProperties() +{ + KPropertiesDialog dialog(m_fileInfo.url(), m_parent); + dialog.exec(); +} + +void TreeViewContextMenu::setShowHiddenFiles(bool show) +{ + m_parent->setShowHiddenFiles(show); +} + +#include "treeviewcontextmenu.moc" diff --git a/src/panels/folders/treeviewcontextmenu.h b/src/panels/folders/treeviewcontextmenu.h new file mode 100644 index 000000000..20a603573 --- /dev/null +++ b/src/panels/folders/treeviewcontextmenu.h @@ -0,0 +1,88 @@ +/*************************************************************************** + * Copyright (C) 2006 by Peter Penz * + * * + * 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 of the License, 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. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#ifndef TREEVIEWCONTEXTMENU_H +#define TREEVIEWCONTEXTMENU_H + +#include +#include + +class TreeViewSidebarPage; + +/** + * @brief Represents the context menu which appears when doing a right + * click on an item of the treeview. + */ +class TreeViewContextMenu : public QObject +{ + Q_OBJECT + +public: + /** + * @parent Pointer to the treeview sidebar page the context menu + * belongs to. + * @fileInfo Pointer to the file item the context menu + * is applied. If 0 is passed, the context menu + * is above the viewport. + */ + TreeViewContextMenu(TreeViewSidebarPage* parent, + const KFileItem& fileInfo); + + virtual ~TreeViewContextMenu(); + + /** Opens the context menu modal. */ + void open(); + +private slots: + /** Cuts the item m_fileInfo. */ + void cut(); + + /** Copies the item m_fileInfo. */ + void copy(); + + /** Paste the clipboard to m_fileInfo. */ + void paste(); + + /** Renames the item m_fileInfo. */ + void rename(); + + /** Moves the item m_fileInfo to the trash. */ + void moveToTrash(); + + /** Deletes the item m_fileInfo. */ + void deleteItem(); + + /** Shows the properties of the item m_fileInfo. */ + void showProperties(); + + /** + * Sets the 'Show Hidden Files' setting for the + * folders panel to \a show. + */ + void setShowHiddenFiles(bool show); + +private: + void populateMimeData(QMimeData* mimeData, bool cut); + +private: + TreeViewSidebarPage* m_parent; + KFileItem m_fileInfo; +}; + +#endif diff --git a/src/panels/folders/treeviewsidebarpage.cpp b/src/panels/folders/treeviewsidebarpage.cpp new file mode 100644 index 000000000..7801a97cc --- /dev/null +++ b/src/panels/folders/treeviewsidebarpage.cpp @@ -0,0 +1,279 @@ +/*************************************************************************** + * Copyright (C) 2006 by Peter Penz * + * * + * 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 of the License, 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. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#include "treeviewsidebarpage.h" + +#include "dolphinmodel.h" +#include "dolphinsortfilterproxymodel.h" +#include "dolphinview.h" +#include "settings/dolphinsettings.h" +#include "dolphin_folderspanelsettings.h" +#include "dolphin_generalsettings.h" +#include "draganddrophelper.h" +#include "folderexpander.h" +#include "renamedialog.h" +#include "sidebartreeview.h" +#include "treeviewcontextmenu.h" + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +TreeViewSidebarPage::TreeViewSidebarPage(QWidget* parent) : + SidebarPage(parent), + m_setLeafVisible(false), + m_mouseButtons(Qt::NoButton), + m_dirLister(0), + m_dolphinModel(0), + m_proxyModel(0), + m_treeView(0), + m_leafDir() +{ + setLayoutDirection(Qt::LeftToRight); +} + +TreeViewSidebarPage::~TreeViewSidebarPage() +{ + FoldersPanelSettings::self()->writeConfig(); + + delete m_proxyModel; + m_proxyModel = 0; + delete m_dolphinModel; + m_dolphinModel = 0; + m_dirLister = 0; // deleted by m_dolphinModel +} + +QSize TreeViewSidebarPage::sizeHint() const +{ + return QSize(200, 400); +} + +void TreeViewSidebarPage::setShowHiddenFiles(bool show) +{ + FoldersPanelSettings::setShowHiddenFiles(show); + if (m_dirLister != 0) { + m_dirLister->setShowingDotFiles(show); + m_dirLister->openUrl(m_dirLister->url(), KDirLister::Reload); + } +} + +bool TreeViewSidebarPage::showHiddenFiles() const +{ + return FoldersPanelSettings::showHiddenFiles(); +} + +void TreeViewSidebarPage::rename(const KFileItem& item) +{ + if (DolphinSettings::instance().generalSettings()->renameInline()) { + const QModelIndex dirIndex = m_dolphinModel->indexForItem(item); + const QModelIndex proxyIndex = m_proxyModel->mapFromSource(dirIndex); + m_treeView->edit(proxyIndex); + } else { + KFileItemList items; + items.append(item); + RenameDialog dialog(this, items); + if (dialog.exec() == QDialog::Accepted) { + const QString& newName = dialog.newName(); + if (!newName.isEmpty()) { + KUrl newUrl = item.url(); + newUrl.setFileName(newName); + KonqOperations::rename(this, item.url(), newUrl); + } + } + } +} + +void TreeViewSidebarPage::setUrl(const KUrl& url) +{ + if (!url.isValid() || (url == SidebarPage::url())) { + return; + } + + SidebarPage::setUrl(url); + if (m_dirLister != 0) { + m_setLeafVisible = true; + loadTree(url); + } +} + +void TreeViewSidebarPage::showEvent(QShowEvent* event) +{ + if (event->spontaneous()) { + SidebarPage::showEvent(event); + return; + } + + if (m_dirLister == 0) { + // Postpone the creating of the dir lister to the first show event. + // This assures that no performance and memory overhead is given when the TreeView is not + // used at all (see TreeViewSidebarPage::setUrl()). + m_dirLister = new KDirLister(); + m_dirLister->setDirOnlyMode(true); + m_dirLister->setAutoUpdate(true); + m_dirLister->setMainWindow(window()); + m_dirLister->setDelayedMimeTypes(true); + m_dirLister->setAutoErrorHandlingEnabled(false, this); + m_dirLister->setShowingDotFiles(FoldersPanelSettings::showHiddenFiles()); + + Q_ASSERT(m_dolphinModel == 0); + m_dolphinModel = new DolphinModel(this); + m_dolphinModel->setDirLister(m_dirLister); + m_dolphinModel->setDropsAllowed(DolphinModel::DropOnDirectory); + connect(m_dolphinModel, SIGNAL(expand(const QModelIndex&)), + this, SLOT(expandToDir(const QModelIndex&))); + + Q_ASSERT(m_proxyModel == 0); + m_proxyModel = new DolphinSortFilterProxyModel(this); + m_proxyModel->setSourceModel(m_dolphinModel); + + Q_ASSERT(m_treeView == 0); + m_treeView = new SidebarTreeView(this); + m_treeView->setModel(m_proxyModel); + m_proxyModel->setSorting(DolphinView::SortByName); + m_proxyModel->setSortOrder(Qt::AscendingOrder); + + new FolderExpander(m_treeView, m_proxyModel); + + connect(m_treeView, SIGNAL(clicked(const QModelIndex&)), + this, SLOT(updateActiveView(const QModelIndex&))); + connect(m_treeView, SIGNAL(urlsDropped(const QModelIndex&, QDropEvent*)), + this, SLOT(dropUrls(const QModelIndex&, QDropEvent*))); + connect(m_treeView, SIGNAL(pressed(const QModelIndex&)), + this, SLOT(updateMouseButtons())); + + QVBoxLayout* layout = new QVBoxLayout(this); + layout->setMargin(0); + layout->addWidget(m_treeView); + } + + loadTree(url()); + SidebarPage::showEvent(event); +} + +void TreeViewSidebarPage::contextMenuEvent(QContextMenuEvent* event) +{ + SidebarPage::contextMenuEvent(event); + + KFileItem item; + const QModelIndex index = m_treeView->indexAt(event->pos()); + if (index.isValid()) { + const QModelIndex dolphinModelIndex = m_proxyModel->mapToSource(index); + item = m_dolphinModel->itemForIndex(dolphinModelIndex); + emit changeSelection(KFileItemList()); + } + + TreeViewContextMenu contextMenu(this, item); + contextMenu.open(); +} + +void TreeViewSidebarPage::updateActiveView(const QModelIndex& index) +{ + const QModelIndex dirIndex = m_proxyModel->mapToSource(index); + const KFileItem item = m_dolphinModel->itemForIndex(dirIndex); + if (!item.isNull()) { + emit changeUrl(item.url(), m_mouseButtons); + } +} + +void TreeViewSidebarPage::dropUrls(const QModelIndex& index, QDropEvent* event) +{ + if (index.isValid()) { + const QModelIndex dirIndex = m_proxyModel->mapToSource(index); + KFileItem item = m_dolphinModel->itemForIndex(dirIndex); + Q_ASSERT(!item.isNull()); + if (item.isDir()) { + DragAndDropHelper::instance().dropUrls(item, item.url(), event, this); + } + } +} + +void TreeViewSidebarPage::expandToDir(const QModelIndex& index) +{ + m_treeView->setExpanded(index, true); + selectLeafDirectory(); + m_treeView->resizeColumnToContents(DolphinModel::Name); +} + +void TreeViewSidebarPage::scrollToLeaf() +{ + const QModelIndex dirIndex = m_dolphinModel->indexForUrl(m_leafDir); + const QModelIndex proxyIndex = m_proxyModel->mapFromSource(dirIndex); + if (proxyIndex.isValid()) { + m_treeView->scrollTo(proxyIndex); + } +} + +void TreeViewSidebarPage::updateMouseButtons() +{ + m_mouseButtons = QApplication::mouseButtons(); +} + +void TreeViewSidebarPage::loadTree(const KUrl& url) +{ + Q_ASSERT(m_dirLister != 0); + m_leafDir = url; + + KUrl baseUrl; + if (url.isLocalFile()) { + // use the root directory as base for local URLs (#150941) + baseUrl = QDir::rootPath(); + } else { + // clear the path for non-local URLs and use it as base + baseUrl = url; + baseUrl.setPath(QString('/')); + } + + if (m_dirLister->url() != baseUrl) { + m_dirLister->stop(); + m_dirLister->openUrl(baseUrl, KDirLister::Reload); + } + m_dolphinModel->expandToUrl(m_leafDir); +} + +void TreeViewSidebarPage::selectLeafDirectory() +{ + const QModelIndex dirIndex = m_dolphinModel->indexForUrl(m_leafDir); + const QModelIndex proxyIndex = m_proxyModel->mapFromSource(dirIndex); + if (!proxyIndex.isValid()) { + return; + } + + if (m_setLeafVisible) { + // Invoke m_treeView->scrollTo(proxyIndex) asynchronously by + // scrollToLeaf(). This assures that the scrolling is done after + // the horizontal scrollbar gets visible (otherwise the scrollbar + // might hide the leaf). + QTimer::singleShot(100, this, SLOT(scrollToLeaf())); + m_setLeafVisible = false; + } + + QItemSelectionModel* selModel = m_treeView->selectionModel(); + selModel->setCurrentIndex(proxyIndex, QItemSelectionModel::ClearAndSelect); +} + +#include "treeviewsidebarpage.moc" diff --git a/src/panels/folders/treeviewsidebarpage.h b/src/panels/folders/treeviewsidebarpage.h new file mode 100644 index 000000000..39f2323ad --- /dev/null +++ b/src/panels/folders/treeviewsidebarpage.h @@ -0,0 +1,135 @@ +/*************************************************************************** + * Copyright (C) 2006 by Peter Penz * + * * + * 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 of the License, 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. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#ifndef TREEVIEWSIDEBARPAGE_H +#define TREEVIEWSIDEBARPAGE_H + +#include +#include + +class KDirLister; +class DolphinModel; + +class DolphinSortFilterProxyModel; +class SidebarTreeView; +class QModelIndex; + +/** + * @brief Shows a tree view of the directories starting from + * the currently selected place. + * + * The tree view is always synchronized with the currently active view + * from the main window. + */ +class TreeViewSidebarPage : public SidebarPage +{ + Q_OBJECT + +public: + TreeViewSidebarPage(QWidget* parent = 0); + virtual ~TreeViewSidebarPage(); + + /** @see QWidget::sizeHint() */ + virtual QSize sizeHint() const; + + void setShowHiddenFiles(bool show); + bool showHiddenFiles() const; + + void rename(const KFileItem& item); + +signals: + /** + * Is emitted if the an URL change is requested. + */ + void changeUrl(const KUrl& url, Qt::MouseButtons buttons); + + /** + * This signal is emitted when the sidebar requests a change in the + * current selection. The file-management view recieving this signal is + * not required to select all listed files, limiting the selection to + * e.g. the current folder. The new selection will be reported via the + * setSelection slot. + */ + void changeSelection(const KFileItemList& selection); + +public slots: + /** + * Changes the current selection inside the tree to \a url. + */ + virtual void setUrl(const KUrl& url); + +protected: + /** @see QWidget::showEvent() */ + virtual void showEvent(QShowEvent* event); + + /** @see QWidget::contextMenuEvent() */ + virtual void contextMenuEvent(QContextMenuEvent* event); + +private slots: + /** + * Updates the active view to the URL + * which is given by the item with the index \a index. + */ + void updateActiveView(const QModelIndex& index); + + /** + * Is emitted if URLs have been dropped + * to the index \a index. + */ + void dropUrls(const QModelIndex& index, QDropEvent* event); + + /** + * Expands the treeview to show the directory + * specified by \a index. + */ + void expandToDir(const QModelIndex& index); + + /** + * Assures that the leaf folder gets visible. + */ + void scrollToLeaf(); + + void updateMouseButtons(); + +private: + /** + * Initializes the base URL of the tree and expands all + * directories until \a url. + * @param url URL of the leaf directory that should get expanded. + */ + void loadTree(const KUrl& url); + + /** + * Selects the current leaf directory m_leafDir and assures + * that the directory is visible if the leaf has been set by + * TreeViewSidebarPage::setUrl(). + */ + void selectLeafDirectory(); + +private: + bool m_setLeafVisible; + Qt::MouseButtons m_mouseButtons; + KDirLister* m_dirLister; + DolphinModel* m_dolphinModel; + DolphinSortFilterProxyModel* m_proxyModel; + SidebarTreeView* m_treeView; + KUrl m_leafDir; +}; + +#endif // TREEVIEWSIDEBARPAGE_H diff --git a/src/panels/information/commenteditwidget.cpp b/src/panels/information/commenteditwidget.cpp new file mode 100644 index 000000000..a55adbea4 --- /dev/null +++ b/src/panels/information/commenteditwidget.cpp @@ -0,0 +1,241 @@ +/*************************************************************************** + * Copyright (C) 2008 by Sebastian Trueg * + * * + * 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 of the License, 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. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#include "commenteditwidget.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + + +class CommentEditWidget::Private +{ +public: + Private( CommentEditWidget* parent ) + : eventLoop( 0 ), + q( parent ) { + } + + QEventLoop* eventLoop; + bool success; + KTextEdit* textEdit; + QToolButton* buttonSave; + QToolButton* buttonCancel; + + QString comment; + + QRect geometryForPopupPos( const QPoint& p ) { + QSize size = q->sizeHint(); + + // we want a little margin + const int margin = KDialog::marginHint(); + size.setHeight( size.height() + margin*2 ); + size.setWidth( size.width() + margin*2 ); + + QRect screen = QApplication::desktop()->screenGeometry( QApplication::desktop()->screenNumber( p ) ); + + // calculate popup position + QPoint pos( p.x() - size.width()/2, p.y() - size.height()/2 ); + + // ensure we do not leave the desktop + if ( pos.x() + size.width() > screen.right() ) { + pos.setX( screen.right() - size.width() ); + } + else if ( pos.x() < screen.left() ) { + pos.setX( screen.left() ); + } + + if ( pos.y() + size.height() > screen.bottom() ) { + pos.setY( screen.bottom() - size.height() ); + } + else if ( pos.y() < screen.top() ) { + pos.setY( screen.top() ); + } + + return QRect( pos, size ); + } + + void _k_saveClicked(); + void _k_cancelClicked(); + +private: + CommentEditWidget* q; +}; + + +void CommentEditWidget::Private::_k_saveClicked() +{ + comment = textEdit->toPlainText(); + success = true; + q->hide(); +} + + +void CommentEditWidget::Private::_k_cancelClicked() +{ + success = false; + q->hide(); +} + + +CommentEditWidget::CommentEditWidget( QWidget* parent ) + : QFrame( parent ), + d( new Private( this ) ) +{ + setFrameStyle( QFrame::Box|QFrame::Plain ); + setWindowFlags( Qt::Popup ); + + d->textEdit = new KTextEdit( this ); + d->textEdit->installEventFilter( this ); + QVBoxLayout* layout = new QVBoxLayout( this ); + layout->setMargin( 0 ); + layout->addWidget( d->textEdit ); + + d->buttonSave = new QToolButton( d->textEdit ); + d->buttonCancel = new QToolButton( d->textEdit ); + d->buttonSave->setToolButtonStyle( Qt::ToolButtonTextBesideIcon ); + d->buttonCancel->setToolButtonStyle( Qt::ToolButtonTextBesideIcon ); + d->buttonSave->setAutoRaise( true ); + d->buttonCancel->setAutoRaise( true ); + d->buttonSave->setIcon( KIcon( "document-save" ) ); + d->buttonCancel->setIcon( KIcon( "edit-delete" ) ); + d->buttonSave->setText( i18nc( "@action:button", "Save" ) ); + d->buttonCancel->setText( i18nc( "@action:button", "Cancel" ) ); + + QFont fnt( font() ); + fnt.setPointSize( fnt.pointSize()-2 ); + d->buttonSave->setFont( fnt ); + d->buttonCancel->setFont( fnt ); + + connect( d->buttonSave, SIGNAL(clicked()), + this, SLOT( _k_saveClicked() ) ); + connect( d->buttonCancel, SIGNAL(clicked()), + this, SLOT( _k_cancelClicked() ) ); +} + + +CommentEditWidget::~CommentEditWidget() +{ + delete d; +} + + +void CommentEditWidget::setComment( const QString& s ) +{ + d->comment = s; +} + + +QString CommentEditWidget::comment() +{ + return d->comment; +} + + +bool CommentEditWidget::exec( const QPoint& pos ) +{ + d->success = false; + d->textEdit->setPlainText( d->comment ); + d->textEdit->setFocus(); + d->textEdit->moveCursor( QTextCursor::End ); + QEventLoop eventLoop; + d->eventLoop = &eventLoop; + setGeometry( d->geometryForPopupPos( pos ) ); + show(); + + QPointer guard = this; + (void) eventLoop.exec(); + if ( !guard.isNull() ) + d->eventLoop = 0; + return d->success; +} + + +void CommentEditWidget::mousePressEvent( QMouseEvent* e ) +{ + // clicking outside of the widget means cancel + if ( !rect().contains( e->pos() ) ) { + d->success = false; + hide(); + } + else { + QWidget::mousePressEvent( e ); + } +} + + +void CommentEditWidget::hideEvent( QHideEvent* e ) +{ + Q_UNUSED( e ); + if ( d->eventLoop ) { + d->eventLoop->exit(); + } +} + + +void CommentEditWidget::updateButtons() +{ + QSize sbs = d->buttonSave->sizeHint(); + QSize cbs = d->buttonCancel->sizeHint(); + + // FIXME: button order + d->buttonCancel->setGeometry( QRect( QPoint( d->textEdit->width() - cbs.width() - frameWidth(), + d->textEdit->height() - cbs.height() - frameWidth() ), + cbs ) ); + d->buttonSave->setGeometry( QRect( QPoint( d->textEdit->width() - cbs.width() - sbs.width() - frameWidth(), + d->textEdit->height() - sbs.height() - frameWidth() ), + sbs ) ); +} + + +void CommentEditWidget::resizeEvent( QResizeEvent* e ) +{ + QWidget::resizeEvent( e ); + updateButtons(); +} + + +bool CommentEditWidget::eventFilter( QObject* watched, QEvent* event ) +{ + if ( watched == d->textEdit && event->type() == QEvent::KeyPress ) { + QKeyEvent* ke = static_cast( event ); + kDebug() << "keypress:" << ke->key() << ke->modifiers(); + if ( ( ke->key() == Qt::Key_Enter || + ke->key() == Qt::Key_Return ) && + ke->modifiers() & Qt::ControlModifier ) { + d->_k_saveClicked(); + return true; + } + } + + return QFrame::eventFilter( watched, event ); +} + +#include "commenteditwidget.moc" diff --git a/src/panels/information/commenteditwidget.h b/src/panels/information/commenteditwidget.h new file mode 100644 index 000000000..18ab8d7b2 --- /dev/null +++ b/src/panels/information/commenteditwidget.h @@ -0,0 +1,62 @@ +/*************************************************************************** + * Copyright (C) 2008 by Sebastian Trueg * + * * + * 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 of the License, 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. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#ifndef _COMMENT_EDIT_WIDGET_H_ +#define _COMMENT_EDIT_WIDGET_H_ + +#include + +class QResizeEvent; +class QMouseEvent; +class QHideEvent; + +class CommentEditWidget : public QFrame +{ + Q_OBJECT + +public: + CommentEditWidget( QWidget* parent = 0 ); + ~CommentEditWidget(); + + void setComment( const QString& s ); + QString comment(); + + /** + * Show the comment widget at position pos. + * \return true if the user chose to save the comment, + * false otherwise. + */ + bool exec( const QPoint& pos ); + + bool eventFilter( QObject* watched, QEvent* event ); + +private: + void updateButtons(); + void resizeEvent( QResizeEvent* ); + void mousePressEvent( QMouseEvent* e ); + void hideEvent( QHideEvent* e ); + + class Private; + Private* const d; + + Q_PRIVATE_SLOT( d, void _k_saveClicked() ) + Q_PRIVATE_SLOT( d, void _k_cancelClicked() ) +}; + +#endif diff --git a/src/panels/information/commentwidget.cpp b/src/panels/information/commentwidget.cpp new file mode 100644 index 000000000..586be63aa --- /dev/null +++ b/src/panels/information/commentwidget.cpp @@ -0,0 +1,114 @@ +/*************************************************************************** + * Copyright (C) 2008 by Sebastian Trueg * + * * + * 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 of the License, 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. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#include "commentwidget.h" +#include "commenteditwidget.h" + +#include +#include +#include +#include +#include + +#include + + +class CommentWidget::Private +{ +public: + Private( CommentWidget* parent ) + : q( parent ) { + } + + void update(); + void _k_slotEnableEditing(); + + QLabel* label; + CommentEditWidget* edit; + + QString comment; + +private: + CommentWidget* q; +}; + + +void CommentWidget::Private::update() +{ + if ( comment.isEmpty() ) { + label->setText( "

" + i18nc( "@label", "Add Comment..." ) + "" ); + } + else { + label->setText( "

" + comment + "

" + i18nc( "@label", "Change Comment..." ) + "" ); + } +} + + +void CommentWidget::Private::_k_slotEnableEditing() +{ + CommentEditWidget w; + w.setComment( comment ); + if ( w.exec( QCursor::pos() ) ) { + comment = w.comment(); + update(); + emit q->commentChanged( comment ); + } +} + + + +CommentWidget::CommentWidget( QWidget* parent ) + : QWidget( parent ), + d( new Private( this ) ) +{ + d->label = new QLabel( this ); + d->label->setWordWrap( true ); + QVBoxLayout* layout = new QVBoxLayout( this ); + layout->setMargin( 0 ); + layout->addWidget( d->label ); + d->update(); + connect( d->label, SIGNAL( linkActivated( const QString& ) ), this, SLOT( _k_slotEnableEditing() ) ); +} + + +CommentWidget::~CommentWidget() +{ + delete d; +} + + +void CommentWidget::setComment( const QString& comment ) +{ + d->comment = comment; + d->update(); +} + + +QString CommentWidget::comment() const +{ + return d->comment; +} + + +bool CommentWidget::eventFilter( QObject* watched, QEvent* event ) +{ + return QWidget::eventFilter( watched, event ); +} + +#include "commentwidget.moc" diff --git a/src/panels/information/commentwidget.h b/src/panels/information/commentwidget.h new file mode 100644 index 000000000..8c588518c --- /dev/null +++ b/src/panels/information/commentwidget.h @@ -0,0 +1,48 @@ +/*************************************************************************** + * Copyright (C) 2008 by Sebastian Trueg * + * * + * 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 of the License, 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. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#ifndef _NEPOMUK_COMMENT_WIDGET_H_ +#define _NEPOMUK_COMMENT_WIDGET_H_ + +#include + +class CommentWidget : public QWidget +{ + Q_OBJECT + +public: + CommentWidget( QWidget* parent = 0 ); + ~CommentWidget(); + + void setComment( const QString& comment ); + QString comment() const; + +Q_SIGNALS: + void commentChanged( const QString& ); + +private: + bool eventFilter( QObject* watched, QEvent* event ); + + class Private; + Private* const d; + + Q_PRIVATE_SLOT( d, void _k_slotEnableEditing() ) +}; + +#endif diff --git a/src/panels/information/infosidebarpage.cpp b/src/panels/information/infosidebarpage.cpp new file mode 100644 index 000000000..9eb35bc8d --- /dev/null +++ b/src/panels/information/infosidebarpage.cpp @@ -0,0 +1,587 @@ +/*************************************************************************** + * Copyright (C) 2006 by Peter Penz * + * * + * 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 of the License, 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. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#include "infosidebarpage.h" + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "settings/dolphinsettings.h" +#include "metadatawidget.h" +#include "metatextlabel.h" +#include "pixmapviewer.h" + +InfoSidebarPage::InfoSidebarPage(QWidget* parent) : + SidebarPage(parent), + m_initialized(false), + m_pendingPreview(false), + m_infoTimer(0), + m_outdatedPreviewTimer(0), + m_shownUrl(), + m_urlCandidate(), + m_fileItem(), + m_selection(), + m_nameLabel(0), + m_preview(0), + m_metaDataWidget(0), + m_metaTextLabel(0) +{ +} + +InfoSidebarPage::~InfoSidebarPage() +{ +} + +QSize InfoSidebarPage::sizeHint() const +{ + QSize size = SidebarPage::sizeHint(); + size.setWidth(minimumSizeHint().width()); + return size; +} + +void InfoSidebarPage::setUrl(const KUrl& url) +{ + SidebarPage::setUrl(url); + if (url.isValid() && !isEqualToShownUrl(url)) { + if (isVisible()) { + cancelRequest(); + m_shownUrl = url; + showItemInfo(); + } else { + m_shownUrl = url; + } + } +} + +void InfoSidebarPage::setSelection(const KFileItemList& selection) +{ + if (!isVisible()) { + return; + } + + if ((selection.count() == 0) && (m_selection.count() == 0)) { + // The selection has not really changed, only the current index. + // QItemSelectionModel emits a signal in this case and it is less + // expensive doing the check this way instead of patching + // DolphinView::emitSelectionChanged(). + return; + } + + m_selection = selection; + + const int count = selection.count(); + if (count == 0) { + if (!isEqualToShownUrl(url())) { + m_shownUrl = url(); + showItemInfo(); + } + } else { + if ((count == 1) && !selection.first().url().isEmpty()) { + m_urlCandidate = selection.first().url(); + } + m_infoTimer->start(); + } +} + +void InfoSidebarPage::requestDelayedItemInfo(const KFileItem& item) +{ + if (!isVisible()) { + return; + } + + cancelRequest(); + + m_fileItem = KFileItem(); + if (item.isNull()) { + // The cursor is above the viewport. If files are selected, + // show information regarding the selection. + if (m_selection.size() > 0) { + m_pendingPreview = false; + m_infoTimer->start(); + } + } else { + const KUrl url = item.url(); + if (url.isValid() && !isEqualToShownUrl(url)) { + m_urlCandidate = item.url(); + m_fileItem = item; + m_infoTimer->start(); + } + } +} + +void InfoSidebarPage::showEvent(QShowEvent* event) +{ + SidebarPage::showEvent(event); + if (!event->spontaneous()) { + if (!m_initialized) { + // do a delayed initialization so that no performance + // penalty is given when Dolphin is started with a closed + // Information Panel + init(); + } + showItemInfo(); + } +} + +void InfoSidebarPage::resizeEvent(QResizeEvent* event) +{ + if (isVisible()) { + // If the text inside the name label or the info label cannot + // get wrapped, then the maximum width of the label is increased + // so that the width of the information sidebar gets increased. + // To prevent this, the maximum width is adjusted to + // the current width of the sidebar. + const int maxWidth = event->size().width() - KDialog::spacingHint() * 4; + m_nameLabel->setMaximumWidth(maxWidth); + + // try to increase the preview as large as possible + m_preview->setSizeHint(QSize(maxWidth, maxWidth)); + m_urlCandidate = m_shownUrl; // reset the URL candidate if a resizing is done + m_infoTimer->start(); + } + + SidebarPage::resizeEvent(event); +} + +void InfoSidebarPage::showItemInfo() +{ + if (!isVisible()) { + return; + } + + cancelRequest(); + + if (showMultipleSelectionInfo()) { + KIconLoader iconLoader; + QPixmap icon = iconLoader.loadIcon("dialog-information", + KIconLoader::NoGroup, + KIconLoader::SizeEnormous); + m_preview->setPixmap(icon); + setNameLabelText(i18ncp("@info", "%1 item selected", "%1 items selected", m_selection.count())); + m_shownUrl = KUrl(); + } else { + const KFileItem item = fileItem(); + const KUrl itemUrl = item.url(); + if (!applyPlace(itemUrl)) { + // try to get a preview pixmap from the item... + m_pendingPreview = true; + + // Mark the currently shown preview as outdated. This is done + // with a small delay to prevent a flickering when the next preview + // can be shown within a short timeframe. + m_outdatedPreviewTimer->start(); + + KIO::PreviewJob* job = KIO::filePreview(KFileItemList() << item, + m_preview->width(), + m_preview->height(), + 0, + 0, + false, + true); + + connect(job, SIGNAL(gotPreview(const KFileItem&, const QPixmap&)), + this, SLOT(showPreview(const KFileItem&, const QPixmap&))); + connect(job, SIGNAL(failed(const KFileItem&)), + this, SLOT(showIcon(const KFileItem&))); + + setNameLabelText(itemUrl.fileName()); + } + } + + showMetaInfo(); +} + +void InfoSidebarPage::slotInfoTimeout() +{ + m_shownUrl = m_urlCandidate; + showItemInfo(); +} + +void InfoSidebarPage::markOutdatedPreview() +{ + KIconEffect iconEffect; + QPixmap disabledPixmap = iconEffect.apply(m_preview->pixmap(), + KIconLoader::Desktop, + KIconLoader::DisabledState); + m_preview->setPixmap(disabledPixmap); +} + +void InfoSidebarPage::showIcon(const KFileItem& item) +{ + m_outdatedPreviewTimer->stop(); + m_pendingPreview = false; + if (!applyPlace(item.url())) { + m_preview->setPixmap(item.pixmap(KIconLoader::SizeEnormous)); + } +} + +void InfoSidebarPage::showPreview(const KFileItem& item, + const QPixmap& pixmap) +{ + m_outdatedPreviewTimer->stop(); + + Q_UNUSED(item); + if (m_pendingPreview) { + m_preview->setPixmap(pixmap); + m_pendingPreview = false; + } +} + +void InfoSidebarPage::slotFileRenamed(const QString& source, const QString& dest) +{ + if (m_shownUrl == KUrl(source)) { + // the currently shown file has been renamed, hence update the item information + // for the renamed file + KFileItem item(KFileItem::Unknown, KFileItem::Unknown, KUrl(dest)); + requestDelayedItemInfo(item); + } +} + +void InfoSidebarPage::slotFilesAdded(const QString& directory) +{ + if (m_shownUrl == KUrl(directory)) { + // If the 'trash' icon changes because the trash has been emptied or got filled, + // the signal filesAdded("trash:/") will be emitted. + KFileItem item(KFileItem::Unknown, KFileItem::Unknown, KUrl(directory)); + requestDelayedItemInfo(item); + } +} + +void InfoSidebarPage::slotFilesChanged(const QStringList& files) +{ + foreach (const QString& fileName, files) { + if (m_shownUrl == KUrl(fileName)) { + showItemInfo(); + break; + } + } +} + +void InfoSidebarPage::slotFilesRemoved(const QStringList& files) +{ + foreach (const QString& fileName, files) { + if (m_shownUrl == KUrl(fileName)) { + // the currently shown item has been removed, show + // the parent directory as fallback + m_shownUrl = url(); + showItemInfo(); + break; + } + } +} + +void InfoSidebarPage::slotEnteredDirectory(const QString& directory) +{ + if (m_shownUrl == KUrl(directory)) { + KFileItem item(KFileItem::Unknown, KFileItem::Unknown, KUrl(directory)); + requestDelayedItemInfo(item); + } +} + +void InfoSidebarPage::slotLeftDirectory(const QString& directory) +{ + if (m_shownUrl == KUrl(directory)) { + // The signal 'leftDirectory' is also emitted when a media + // has been unmounted. In this case no directory change will be + // done in Dolphin, but the Information Panel must be updated to + // indicate an invalid directory. + m_shownUrl = url(); + showItemInfo(); + } +} + +bool InfoSidebarPage::applyPlace(const KUrl& url) +{ + KFilePlacesModel* placesModel = DolphinSettings::instance().placesModel(); + int count = placesModel->rowCount(); + + for (int i = 0; i < count; ++i) { + QModelIndex index = placesModel->index(i, 0); + + if (url.equals(placesModel->url(index), KUrl::CompareWithoutTrailingSlash)) { + setNameLabelText(placesModel->text(index)); + m_preview->setPixmap(placesModel->icon(index).pixmap(128, 128)); + return true; + } + } + + return false; +} + +void InfoSidebarPage::cancelRequest() +{ + m_infoTimer->stop(); +} + +void InfoSidebarPage::showMetaInfo() +{ + m_metaTextLabel->clear(); + + if (showMultipleSelectionInfo()) { + if (m_metaDataWidget != 0) { + KUrl::List urls; + foreach (const KFileItem& item, m_selection) { + urls.append(item.targetUrl()); + } + m_metaDataWidget->setFiles(urls); + } + + quint64 totalSize = 0; + foreach (const KFileItem& item, m_selection) { + // Only count the size of files, not dirs to match what + // DolphinViewContainer::selectionStatusBarText() does. + if (!item.isDir() && !item.isLink()) { + totalSize += item.size(); + } + } + m_metaTextLabel->add(i18nc("@label", "Total size:"), KIO::convertSize(totalSize)); + } else { + const KFileItem item = fileItem(); + if (item.isDir()) { + m_metaTextLabel->add(i18nc("@label", "Type:"), i18nc("@label", "Folder")); + m_metaTextLabel->add(i18nc("@label", "Modified:"), item.timeString()); + } else { + m_metaTextLabel->add(i18nc("@label", "Type:"), item.mimeComment()); + + m_metaTextLabel->add(i18nc("@label", "Size:"), KIO::convertSize(item.size())); + m_metaTextLabel->add(i18nc("@label", "Modified:"), item.timeString()); + + if (item.isLocalFile()) { + // TODO: See convertMetaInfo below, find a way to display only interesting information + // in a readable way + const KFileMetaInfo::WhatFlags flags = KFileMetaInfo::Fastest | + KFileMetaInfo::TechnicalInfo | + KFileMetaInfo::ContentInfo; + const QString path = item.url().path(); + const KFileMetaInfo fileMetaInfo(path, QString(), flags); + if (fileMetaInfo.isValid()) { + const QHash& items = fileMetaInfo.items(); + QHash::const_iterator it = items.constBegin(); + const QHash::const_iterator end = items.constEnd(); + QString labelText; + while (it != end) { + const KFileMetaInfoItem& metaInfoItem = it.value(); + const QVariant& value = metaInfoItem.value(); + if (value.isValid() && convertMetaInfo(metaInfoItem.name(), labelText)) { + m_metaTextLabel->add(labelText, value.toString()); + } + ++it; + } + } + } + } + + if (m_metaDataWidget != 0) { + m_metaDataWidget->setFile(item.targetUrl()); + } + } +} + +bool InfoSidebarPage::convertMetaInfo(const QString& key, QString& text) const +{ + struct MetaKey { + const char* key; + QString text; + }; + + // sorted list of keys, where its data should be shown + static const MetaKey keys[] = { + { "http://freedesktop.org/standards/xesam/1.0/core#album", i18nc("@label", "Album:") }, + { "http://freedesktop.org/standards/xesam/1.0/core#artist", i18nc("@label", "Artist:") }, + { "http://freedesktop.org/standards/xesam/1.0/core#genre", i18nc("@label", "Genre:") }, + { "http://freedesktop.org/standards/xesam/1.0/core#height", i18nc("@label", "Height:") }, + { "http://freedesktop.org/standards/xesam/1.0/core#lineCount", i18nc("@label", "Lines:") }, + { "http://freedesktop.org/standards/xesam/1.0/core#title", i18nc("@label", "Title:") }, + { "http://freedesktop.org/standards/xesam/1.0/core#type", i18nc("@label", "Type:") }, + { "http://freedesktop.org/standards/xesam/1.0/core#trackNumber", i18nc("@label", "Track:") }, + { "http://freedesktop.org/standards/xesam/1.0/core#width", i18nc("@label", "Width:") } + }; + + // do a binary search for the key... + int top = 0; + int bottom = sizeof(keys) / sizeof(MetaKey) - 1; + while (top <= bottom) { + const int middle = (top + bottom) / 2; + const int result = key.compare(keys[middle].key); + if (result < 0) { + bottom = middle - 1; + } else if (result > 0) { + top = middle + 1; + } else { + text = keys[middle].text; + return true; + } + } + + return false; +} + +KFileItem InfoSidebarPage::fileItem() const +{ + if (!m_fileItem.isNull()) { + return m_fileItem; + } + + if (!m_selection.isEmpty()) { + Q_ASSERT(m_selection.count() == 1); + return m_selection.first(); + } + + // no item is hovered and no selection has been done: provide + // an item for the directory represented by m_shownUrl + KFileItem item(KFileItem::Unknown, KFileItem::Unknown, m_shownUrl); + item.refresh(); + return item; +} + +bool InfoSidebarPage::showMultipleSelectionInfo() const +{ + return m_fileItem.isNull() && (m_selection.count() > 1); +} + +bool InfoSidebarPage::isEqualToShownUrl(const KUrl& url) const +{ + return m_shownUrl.equals(url, KUrl::CompareWithoutTrailingSlash); +} + +void InfoSidebarPage::setNameLabelText(const QString& text) +{ + QTextOption textOption; + textOption.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere); + + QTextLayout textLayout(text); + textLayout.setFont(m_nameLabel->font()); + textLayout.setTextOption(textOption); + + QString wrappedText; + wrappedText.reserve(text.length()); + + // wrap the text to fit into the width of m_nameLabel + textLayout.beginLayout(); + QTextLine line = textLayout.createLine(); + while (line.isValid()) { + line.setLineWidth(m_nameLabel->width()); + wrappedText += text.mid(line.textStart(), line.textLength()); + + line = textLayout.createLine(); + if (line.isValid()) { + wrappedText += QChar::LineSeparator; + } + } + textLayout.endLayout(); + + m_nameLabel->setText(wrappedText); +} + +void InfoSidebarPage::init() +{ + const int spacing = KDialog::spacingHint(); + + m_infoTimer = new QTimer(this); + m_infoTimer->setInterval(300); + m_infoTimer->setSingleShot(true); + connect(m_infoTimer, SIGNAL(timeout()), + this, SLOT(slotInfoTimeout())); + + // Initialize timer for disabling an outdated preview with a small + // delay. This prevents flickering if the new preview can be generated + // within a very small timeframe. + m_outdatedPreviewTimer = new QTimer(this); + m_outdatedPreviewTimer->setInterval(300); + m_outdatedPreviewTimer->setSingleShot(true); + connect(m_outdatedPreviewTimer, SIGNAL(timeout()), + this, SLOT(markOutdatedPreview())); + + QVBoxLayout* layout = new QVBoxLayout; + layout->setSpacing(spacing); + + // name + m_nameLabel = new QLabel(this); + QFont font = m_nameLabel->font(); + font.setBold(true); + m_nameLabel->setFont(font); + m_nameLabel->setAlignment(Qt::AlignHCenter); + m_nameLabel->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); + + // preview + m_preview = new PixmapViewer(this); + m_preview->setMinimumWidth(KIconLoader::SizeEnormous + KIconLoader::SizeMedium); + m_preview->setMinimumHeight(KIconLoader::SizeEnormous); + + if (MetaDataWidget::metaDataAvailable()) { + // rating, comment and tags + m_metaDataWidget = new MetaDataWidget(this); + m_metaDataWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); + } + + // general meta text information + m_metaTextLabel = new MetaTextLabel(this); + m_metaTextLabel->setMinimumWidth(spacing); + m_metaTextLabel->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); + + layout->addWidget(m_nameLabel); + layout->addWidget(new KSeparator(this)); + layout->addWidget(m_preview); + layout->addWidget(new KSeparator(this)); + if (m_metaDataWidget != 0) { + layout->addWidget(m_metaDataWidget); + layout->addWidget(new KSeparator(this)); + } + layout->addWidget(m_metaTextLabel); + + // ensure that widgets in the information side bar are aligned towards the top + layout->addStretch(1); + setLayout(layout); + + org::kde::KDirNotify* dirNotify = new org::kde::KDirNotify(QString(), QString(), + QDBusConnection::sessionBus(), this); + connect(dirNotify, SIGNAL(FileRenamed(QString, QString)), SLOT(slotFileRenamed(QString, QString))); + connect(dirNotify, SIGNAL(FilesAdded(QString)), SLOT(slotFilesAdded(QString))); + connect(dirNotify, SIGNAL(FilesChanged(QStringList)), SLOT(slotFilesChanged(QStringList))); + connect(dirNotify, SIGNAL(FilesRemoved(QStringList)), SLOT(slotFilesRemoved(QStringList))); + connect(dirNotify, SIGNAL(enteredDirectory(QString)), SLOT(slotEnteredDirectory(QString))); + connect(dirNotify, SIGNAL(leftDirectory(QString)), SLOT(slotLeftDirectory(QString))); + + m_initialized = true; +} + +#include "infosidebarpage.moc" diff --git a/src/panels/information/infosidebarpage.h b/src/panels/information/infosidebarpage.h new file mode 100644 index 000000000..879a245ad --- /dev/null +++ b/src/panels/information/infosidebarpage.h @@ -0,0 +1,194 @@ +/*************************************************************************** + * Copyright (C) 2006 by Peter Penz * + * * + * 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 of the License, 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. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#ifndef INFOSIDEBARPAGE_H +#define INFOSIDEBARPAGE_H + +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +class QPixmap; +class QString; +class KFileItem; +class QLabel; +class PixmapViewer; +class MetaDataWidget; +class MetaTextLabel; + +/** + * @brief Sidebar for showing meta information of one ore more selected items. + */ +class InfoSidebarPage : public SidebarPage +{ + Q_OBJECT + +public: + explicit InfoSidebarPage(QWidget* parent = 0); + virtual ~InfoSidebarPage(); + + /** @see QWidget::sizeHint() */ + virtual QSize sizeHint() const; + +public slots: + /** @see SidebarPage::setUrl() */ + virtual void setUrl(const KUrl& url); + + /** + * This is invoked to inform the sidebar that the user has selected a new + * set of items. + */ + void setSelection(const KFileItemList& selection); + + /** + * Does a delayed request of information for the item \a item. + * If within this delay InfoSidebarPage::setUrl() or InfoSidebarPage::setSelection() + * are invoked, then the request will be skipped. Requesting a delayed item information + * makes sense when hovering items. + */ + void requestDelayedItemInfo(const KFileItem& item); + +protected: + /** @see QWidget::showEvent() */ + virtual void showEvent(QShowEvent* event); + + /** @see QWidget::resizeEvent() */ + virtual void resizeEvent(QResizeEvent* event); + +private slots: + /** + * Shows the information for the item of the URL which has been provided by + * InfoSidebarPage::requestItemInfo() and provides default actions. + */ + void showItemInfo(); + + /** + * Triggered if the request for item information has timed out. + * @see InfoSidebarPage::requestDelayedItemInfo() + */ + void slotInfoTimeout(); + + /** + * Marks the currently shown preview as outdated + * by greying the content. + */ + void markOutdatedPreview(); + + /** + * Is invoked if no preview is available for the item. In this + * case the icon will be shown. + */ + void showIcon(const KFileItem& item); + + /** + * Is invoked if a preview is available for the item. The preview + * \a pixmap is shown inside the info page. + */ + void showPreview(const KFileItem& item, const QPixmap& pixmap); + + void slotFileRenamed(const QString& source, const QString& dest); + void slotFilesAdded(const QString& directory); + void slotFilesChanged(const QStringList& files); + void slotFilesRemoved(const QStringList& files); + void slotEnteredDirectory(const QString& directory); + void slotLeftDirectory(const QString& directory); + +private: + /** + * Checks whether the an URL is repesented by a place. If yes, + * then the place icon and name are shown instead of a preview. + * @return True, if the URL represents exactly a place. + * @param url The url to check. + */ + bool applyPlace(const KUrl& url); + + /** Assures that any pending item information request is cancelled. */ + void cancelRequest(); + + /** + * Shows the meta information for the current shown item inside + * a label. + */ + void showMetaInfo(); + + /** + * Converts the meta key \a key to a readable format into \a text. + * Returns true, if the string \a key represents a meta information + * that should be shown. If false is returned, \a text is not modified. + */ + bool convertMetaInfo(const QString& key, QString& text) const; + + /** + * Returns the item for file where the preview and meta information + * should be received, if InfoSidebarPage::showMultipleSelectionInfo() + * returns false. + */ + KFileItem fileItem() const; + + /** + * Returns true, if the meta information should be shown for + * the multiple selected items that are stored in + * m_selection. If true is returned, it is assured that + * m_selection.count() > 1. If false is returned, the meta + * information should be shown for the file + * InfosidebarPage::fileUrl(); + */ + bool showMultipleSelectionInfo() const; + + /** + * Returns true, if \a url is equal to the shown URL m_shownUrl. + */ + bool isEqualToShownUrl(const KUrl& url) const; + + /** + * Sets the text for the label \a m_nameLabel and assures that the + * text is split in a way that it can be wrapped within the + * label width (QLabel::setWordWrap() does not work if the + * text represents one extremely long word). + */ + void setNameLabelText(const QString& text); + + void init(); + +private: + bool m_initialized; + bool m_pendingPreview; + QTimer* m_infoTimer; + QTimer* m_outdatedPreviewTimer; + KUrl m_shownUrl; // URL that is shown as info + KUrl m_urlCandidate; // URL candidate that will replace m_shownURL after a delay + KFileItem m_fileItem; // file item for m_shownUrl if available (otherwise null) + KFileItemList m_selection; + + QLabel* m_nameLabel; + PixmapViewer* m_preview; + MetaDataWidget* m_metaDataWidget; + MetaTextLabel* m_metaTextLabel; +}; + +#endif // INFOSIDEBARPAGE_H diff --git a/src/panels/information/metadatawidget.cpp b/src/panels/information/metadatawidget.cpp new file mode 100644 index 000000000..44a4c029f --- /dev/null +++ b/src/panels/information/metadatawidget.cpp @@ -0,0 +1,281 @@ +/*************************************************************************** + * Copyright (C) 2007 by Sebastian Trueg * + * * + * 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 of the License, 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. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#include "metadatawidget.h" + +#include "commentwidget.h" + +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#ifdef HAVE_NEPOMUK +#include "nepomukmassupdatejob.h" +#include +#include +#include +#include +#include +#include +#include "resourcetaggingwidget.h" +#endif + + +bool MetaDataWidget::metaDataAvailable() +{ +#ifdef HAVE_NEPOMUK + return !Nepomuk::ResourceManager::instance()->init(); +#else + return false; +#endif +} + + +class MetaDataWidget::Private +{ +public: +#ifdef HAVE_NEPOMUK + void loadComment(const QString& comment); + + CommentWidget* editComment; + KRatingWidget* ratingWidget; + Nepomuk::ResourceTaggingWidget* tagWidget; + + // shared data between the GUI-thread and + // the loader-thread (see LoadFilesThread): + QMutex mutex; + struct SharedData + { + int rating; + QString comment; + QList fileRes; + QMap files; + } sharedData; + + /** + * Loads the meta data of files and writes + * the result into a shared data pool that + * can be used by the widgets in the GUI thread. + */ + class LoadFilesThread : public QThread + { + public: + LoadFilesThread(SharedData* sharedData, QMutex* mutex); + void setFiles(const KUrl::List& urls); + virtual void run(); + + private: + SharedData* m_sharedData; + QMutex* m_mutex; + KUrl::List m_urls; + }; + + LoadFilesThread* loadFilesThread; +#endif +}; + +#ifdef HAVE_NEPOMUK +void MetaDataWidget::Private::loadComment(const QString& comment) +{ + editComment->setComment( comment ); +} + +MetaDataWidget::Private::LoadFilesThread::LoadFilesThread( + MetaDataWidget::Private::SharedData* sharedData, + QMutex* mutex) : + m_sharedData(sharedData), + m_mutex(mutex), + m_urls() +{ +} + +void MetaDataWidget::Private::LoadFilesThread::setFiles(const KUrl::List& urls) +{ + QMutexLocker locker( m_mutex ); + m_urls = urls; +} + +void MetaDataWidget::Private::LoadFilesThread::run() +{ + QMutexLocker locker( m_mutex ); + const KUrl::List urls = m_urls; + locker.unlock(); + + bool first = true; + QList fileRes; + QMap files; + unsigned int rating = 0; + QString comment; + Q_FOREACH( const KUrl &url, urls ) { + Nepomuk::Resource file( url, Soprano::Vocabulary::Xesam::File() ); + files.insert( url, file ); + fileRes.append( file ); + + if ( !first && rating != file.rating() ) { + rating = 0; // reset rating + } + else if ( first ) { + rating = file.rating(); + } + + if ( !first && comment != file.description() ) { + comment.clear(); + } + else if ( first ) { + comment = file.description(); + } + first = false; + } + + locker.relock(); + m_sharedData->rating = rating; + m_sharedData->comment = comment; + m_sharedData->fileRes = fileRes; + m_sharedData->files = files; +} +#endif + +MetaDataWidget::MetaDataWidget(QWidget* parent) : + QWidget(parent) +{ +#ifdef HAVE_NEPOMUK + d = new Private; + d->editComment = new CommentWidget(this); + d->editComment->setFocusPolicy(Qt::ClickFocus); + d->ratingWidget = new KRatingWidget(this); + d->ratingWidget->setAlignment( Qt::AlignCenter ); + d->tagWidget = new Nepomuk::ResourceTaggingWidget(this); + connect(d->ratingWidget, SIGNAL(ratingChanged(unsigned int)), this, SLOT(slotRatingChanged(unsigned int))); + connect(d->editComment, SIGNAL(commentChanged(const QString&)), this, SLOT(slotCommentChanged(const QString&))); + connect( d->tagWidget, SIGNAL( tagClicked( const Nepomuk::Tag& ) ), this, SLOT( slotTagClicked( const Nepomuk::Tag& ) ) ); + + d->sharedData.rating = 0; + d->loadFilesThread = new Private::LoadFilesThread(&d->sharedData, &d->mutex); + connect(d->loadFilesThread, SIGNAL(finished()), this, SLOT(slotLoadingFinished())); + + QVBoxLayout* lay = new QVBoxLayout(this); + lay->setMargin(0); + lay->addWidget(d->ratingWidget); + lay->addWidget(d->editComment); + lay->addWidget( d->tagWidget ); +#else + d = 0; +#endif +} + + +MetaDataWidget::~MetaDataWidget() +{ +#ifdef HAVE_NEPOMUK + delete d->loadFilesThread; +#endif + delete d; +} + + +void MetaDataWidget::setFile(const KUrl& url) +{ + kDebug() << url; + KUrl::List urls; + urls.append( url ); + setFiles( urls ); +} + +void MetaDataWidget::setFiles(const KUrl::List& urls) +{ +#ifdef HAVE_NEPOMUK + d->loadFilesThread->setFiles( urls ); + d->loadFilesThread->start(); +#else + Q_UNUSED( urls ); +#endif +} + + +void MetaDataWidget::slotCommentChanged( const QString& s ) +{ +#ifdef HAVE_NEPOMUK + QMutexLocker locker( &d->mutex ); + Nepomuk::MassUpdateJob* job = Nepomuk::MassUpdateJob::commentResources( d->sharedData.files.values(), s ); + connect( job, SIGNAL( result( KJob* ) ), + this, SLOT( metadataUpdateDone() ) ); + setEnabled( false ); // no updates during execution + job->start(); +#else + Q_UNUSED( s ); +#endif +} + + +void MetaDataWidget::slotRatingChanged(unsigned int rating) +{ +#ifdef HAVE_NEPOMUK + QMutexLocker locker( &d->mutex ); + Nepomuk::MassUpdateJob* job = Nepomuk::MassUpdateJob::rateResources( d->sharedData.files.values(), rating ); + connect( job, SIGNAL( result( KJob* ) ), + this, SLOT( metadataUpdateDone() ) ); + setEnabled( false ); // no updates during execution + job->start(); +#else + Q_UNUSED( rating ); +#endif +} + + +void MetaDataWidget::metadataUpdateDone() +{ + setEnabled( true ); +} + + +bool MetaDataWidget::eventFilter(QObject* obj, QEvent* event) +{ + return QWidget::eventFilter(obj, event); +} + + +void MetaDataWidget::slotTagClicked( const Nepomuk::Tag& tag ) +{ + Q_UNUSED( tag ); +#ifdef HAVE_NEPOMUK + d->tagWidget->showTagPopup( QCursor::pos() ); +#endif +} + +void MetaDataWidget::slotLoadingFinished() +{ +#ifdef HAVE_NEPOMUK + QMutexLocker locker( &d->mutex ); + d->ratingWidget->setRating( d->sharedData.rating ); + d->loadComment( d->sharedData.comment ); + d->tagWidget->setResources( d->sharedData.fileRes ); +#endif +} + +#include "metadatawidget.moc" diff --git a/src/panels/information/metadatawidget.h b/src/panels/information/metadatawidget.h new file mode 100644 index 000000000..881c23c42 --- /dev/null +++ b/src/panels/information/metadatawidget.h @@ -0,0 +1,72 @@ +/*************************************************************************** + * Copyright (C) 2007 by Sebastian Trueg * + * * + * 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 of the License, 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. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#ifndef METADATA_WIDGET_H +#define METADATA_WIDGET_H + +#include + +#include + +namespace Nepomuk { + class Tag; +} + +class MetaDataWidget : public QWidget +{ + Q_OBJECT + +public: + MetaDataWidget(QWidget* parent = 0); + virtual ~MetaDataWidget(); + + /** + * \return true if the KMetaData system could be found and initialized. + * false if KMetaData was not available at compile time or if it has not + * been initialized properly. + */ + static bool metaDataAvailable(); + +public Q_SLOTS: + void setFile(const KUrl& url); + void setFiles(const KUrl::List& urls); + +signals: + /** + * This signal gets emitted if the metadata for the set file was changed on the + * outside. NOT IMPLEMENTED YET. + */ + void metaDataChanged(); + +private Q_SLOTS: + void slotCommentChanged(const QString&); + void slotRatingChanged(unsigned int rating); + void metadataUpdateDone(); + void slotTagClicked( const Nepomuk::Tag& ); + void slotLoadingFinished(); + +protected: + bool eventFilter(QObject* obj, QEvent* event); + +private: + class Private; + Private* d; +}; + +#endif diff --git a/src/panels/information/metatextlabel.cpp b/src/panels/information/metatextlabel.cpp new file mode 100644 index 000000000..66f12db90 --- /dev/null +++ b/src/panels/information/metatextlabel.cpp @@ -0,0 +1,135 @@ +/*************************************************************************** + * Copyright (C) 2008 by Peter Penz * + * * + * 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 of the License, 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. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#include "metatextlabel.h" + +#include +#include + +#include +#include +#include +#include + +MetaTextLabel::MetaTextLabel(QWidget* parent) : + QWidget(parent), + m_minimumHeight(0), + m_metaInfos() +{ + setFont(KGlobalSettings::smallestReadableFont()); +} + +MetaTextLabel::~MetaTextLabel() +{ +} + +void MetaTextLabel::clear() +{ + m_minimumHeight = 0; + m_metaInfos.clear(); + update(); +} + +void MetaTextLabel::add(const QString& labelText, const QString& infoText) +{ + MetaInfo metaInfo; + metaInfo.label = labelText; + metaInfo.info = infoText; + + m_metaInfos.append(metaInfo); + + m_minimumHeight += requiredHeight(metaInfo); + setMinimumHeight(m_minimumHeight); + + update(); +} + +void MetaTextLabel::paintEvent(QPaintEvent* event) +{ + QWidget::paintEvent(event); + + QPainter painter(this); + + const QColor infoColor = palette().color(QPalette::Foreground); + QColor labelColor = infoColor; + labelColor.setAlpha(128); + + int y = 0; + const int infoWidth = width() / 2; + const int labelWidth = infoWidth - 2 * Spacing; + const int infoX = infoWidth; + const int maxHeight = fontMetrics().height() * 5; + + QRect boundingRect; + foreach (const MetaInfo& metaInfo, m_metaInfos) { + // draw label (e. g. "Date:") + painter.setPen(labelColor); + painter.drawText(0, y, labelWidth, maxHeight, + Qt::AlignTop | Qt::AlignRight | Qt::TextWordWrap, + metaInfo.label); + + // draw information (e. g. "2008-11-09 20:12") + painter.setPen(infoColor); + painter.drawText(infoX, y, infoWidth, maxHeight, + Qt::AlignTop | Qt::AlignLeft | Qt::TextWordWrap, + metaInfo.info, + &boundingRect); + + y += boundingRect.height() + Spacing; + } +} + +void MetaTextLabel::resizeEvent(QResizeEvent* event) +{ + QWidget::resizeEvent(event); + + m_minimumHeight = 0; + foreach (const MetaInfo& metaInfo, m_metaInfos) { + m_minimumHeight += requiredHeight(metaInfo); + } + setMinimumHeight(m_minimumHeight); +} + +int MetaTextLabel::requiredHeight(const MetaInfo& metaInfo) const +{ + QTextOption textOption; + textOption.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere); + + qreal height = 0; + const int leading = fontMetrics().leading(); + const int availableWidth = width() / 2; + + QTextLayout textLayout(metaInfo.info); + textLayout.setFont(font()); + textLayout.setTextOption(textOption); + + textLayout.beginLayout(); + QTextLine line = textLayout.createLine(); + while (line.isValid()) { + line.setLineWidth(availableWidth); + height += leading; + height += line.height(); + line = textLayout.createLine(); + } + textLayout.endLayout(); + + return static_cast(height) + Spacing; +} + +#include "metatextlabel.moc" diff --git a/src/panels/information/metatextlabel.h b/src/panels/information/metatextlabel.h new file mode 100644 index 000000000..f70d29d8e --- /dev/null +++ b/src/panels/information/metatextlabel.h @@ -0,0 +1,64 @@ +/*************************************************************************** + * Copyright (C) 2008 by Peter Penz * + * * + * 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 of the License, 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. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#ifndef METATEXTLABEL_H +#define METATEXTLABEL_H + +#include + +/** + * @brief Displays general meta in several lines. + * + * Each line contains a label and the meta information. + */ +class MetaTextLabel : public QWidget +{ + Q_OBJECT + +public: + explicit MetaTextLabel(QWidget* parent = 0); + virtual ~MetaTextLabel(); + + void clear(); + void add(const QString& labelText, const QString& infoText); + +protected: + virtual void paintEvent(QPaintEvent* event); + virtual void resizeEvent(QResizeEvent* event); + +private: + enum { Spacing = 2 }; + + struct MetaInfo + { + QString label; + QString info; + }; + + int m_minimumHeight; + QList m_metaInfos; + + /** + * Returns the required height in pixels for \a metaInfo to + * fit into the available width of the widget. + */ + int requiredHeight(const MetaInfo& metaInfo) const; +}; + +#endif diff --git a/src/panels/information/nepomukmassupdatejob.cpp b/src/panels/information/nepomukmassupdatejob.cpp new file mode 100644 index 000000000..5c883fd4b --- /dev/null +++ b/src/panels/information/nepomukmassupdatejob.cpp @@ -0,0 +1,163 @@ +/*************************************************************************** + * Copyright (C) 2008 by Sebastian Trueg * + * * + * 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 of the License, 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. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#include "nepomukmassupdatejob.h" + +#include +#include + +#include +#include + + +Nepomuk::MassUpdateJob::MassUpdateJob( QObject* parent ) + : KJob( parent ), + m_index( -1 ) +{ + kDebug(); + setCapabilities( Killable|Suspendable ); + connect( &m_processTimer, SIGNAL( timeout() ), + this, SLOT( slotNext() ) ); +} + + +Nepomuk::MassUpdateJob::~MassUpdateJob() +{ + kDebug(); +} + + +void Nepomuk::MassUpdateJob::setFiles( const KUrl::List& urls ) +{ + m_resources.clear(); + foreach( const KUrl &url, urls ) { + m_resources.append( Resource( url ) ); + } + setTotalAmount( KJob::Files, m_resources.count() ); +} + + +void Nepomuk::MassUpdateJob::setResources( const QList& rl ) +{ + m_resources = rl; + setTotalAmount( KJob::Files, m_resources.count() ); +} + + +void Nepomuk::MassUpdateJob::setProperties( const QList >& props ) +{ + m_properties = props; +} + + +void Nepomuk::MassUpdateJob::start() +{ + if ( m_index < 0 ) { + kDebug(); + emit description( this, + i18nc("@info:progress", "Changing annotations") ); + m_index = 0; + m_processTimer.start(); + } + else { + kDebug() << "Job has already been started"; + } +} + + +bool Nepomuk::MassUpdateJob::doKill() +{ + if ( m_index > 0 ) { + m_processTimer.stop(); + m_index = -1; + return true; + } + else { + return false; + } +} + + +bool Nepomuk::MassUpdateJob::doSuspend() +{ + m_processTimer.stop(); + return true; +} + + +bool Nepomuk::MassUpdateJob::doResume() +{ + if ( m_index > 0 ) { + m_processTimer.start(); + return true; + } + else { + return false; + } +} + + +void Nepomuk::MassUpdateJob::slotNext() +{ + if ( !isSuspended() ) { + if ( m_index < m_resources.count() ) { + Nepomuk::Resource& res = m_resources[m_index]; + for ( int i = 0; i < m_properties.count(); ++i ) { + res.setProperty( m_properties[i].first, m_properties[i].second ); + } + ++m_index; + setProcessedAmount( KJob::Files, m_index ); + } + else if ( m_index >= m_resources.count() ) { + kDebug() << "done"; + m_index = -1; + m_processTimer.stop(); + emitResult(); + } + } +} + + +Nepomuk::MassUpdateJob* Nepomuk::MassUpdateJob::tagResources( const QList& rl, const QList& tags ) +{ + Nepomuk::MassUpdateJob* job = new Nepomuk::MassUpdateJob(); + job->setResources( rl ); + job->setProperties( QList >() << qMakePair( QUrl( Nepomuk::Resource::tagUri() ), Nepomuk::Variant( convertResourceList( tags ) ) ) ); + return job; +} + + +Nepomuk::MassUpdateJob* Nepomuk::MassUpdateJob::rateResources( const QList& rl, int rating ) +{ + Nepomuk::MassUpdateJob* job = new Nepomuk::MassUpdateJob(); + job->setResources( rl ); + job->setProperties( QList >() << qMakePair( QUrl( Nepomuk::Resource::ratingUri() ), Nepomuk::Variant( rating ) ) ); + return job; +} + + +Nepomuk::MassUpdateJob* Nepomuk::MassUpdateJob::commentResources( const QList& rl, const QString& comment ) +{ + Nepomuk::MassUpdateJob* job = new Nepomuk::MassUpdateJob(); + job->setResources( rl ); + job->setProperties( QList >() << qMakePair( QUrl( Nepomuk::Resource::descriptionUri() ), Nepomuk::Variant( comment ) ) ); + return job; +} + +#include "nepomukmassupdatejob.moc" diff --git a/src/panels/information/nepomukmassupdatejob.h b/src/panels/information/nepomukmassupdatejob.h new file mode 100644 index 000000000..a19fa5ff9 --- /dev/null +++ b/src/panels/information/nepomukmassupdatejob.h @@ -0,0 +1,85 @@ +/*************************************************************************** + * Copyright (C) 2008 by Sebastian Trueg * + * * + * 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 of the License, 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. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#ifndef _NEPOMUK_MASS_UPDATE_JOB_H_ +#define _NEPOMUK_MASS_UPDATE_JOB_H_ + +#include +#include + +#include +#include +#include + +#include +#include + + +namespace Nepomuk { + class MassUpdateJob : public KJob + { + Q_OBJECT + + public: + MassUpdateJob( QObject* parent = 0 ); + ~MassUpdateJob(); + + /** + * Set a list of files to change + * This has the same effect as using setResources + * with a list of manually created resources. + */ + void setFiles( const KUrl::List& urls ); + + /** + * Set a list of resources to change. + */ + void setResources( const QList& ); + + /** + * Set the properties to change in the mass update. + */ + void setProperties( const QList >& props ); + + /** + * Actually start the job. + */ + void start(); + + static MassUpdateJob* tagResources( const QList&, const QList& tags ); + static MassUpdateJob* commentResources( const QList&, const QString& comment ); + static MassUpdateJob* rateResources( const QList&, int rating ); + + protected: + bool doKill(); + bool doSuspend(); + bool doResume(); + + private Q_SLOTS: + void slotNext(); + + private: + QList m_resources; + QList > m_properties; + int m_index; + QTimer m_processTimer; + }; +} + +#endif diff --git a/src/panels/information/newtagdialog.cpp b/src/panels/information/newtagdialog.cpp new file mode 100644 index 000000000..8785d578c --- /dev/null +++ b/src/panels/information/newtagdialog.cpp @@ -0,0 +1,95 @@ +/* + Copyright (C) 2008 by Sebastian Trueg + + 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. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "newtagdialog.h" + +#include + +#include +#include +#include + + +NewTagDialog::NewTagDialog( QWidget* parent ) + : KDialog( parent ) +{ + setCaption( i18nc( "@title:window", "Create New Tag" ) ); + setButtons( Ok|Cancel ); + enableButtonOk( false ); + + setupUi( mainWidget() ); + + connect( m_editTagLabel, SIGNAL( textChanged(const QString&) ), + this, SLOT( slotLabelChanged(const QString&) ) ); + + // TODO: use KGlobal::config() if NewTagDialog will be moved to kdelibs (KDE 4.2?) + KConfigGroup group(KSharedConfig::openConfig("dolphinrc"), "NewTagDialog"); + restoreDialogSize(group); +} + + +NewTagDialog::~NewTagDialog() +{ + // TODO: use KGlobal::config() if NewTagDialog will be moved to kdelibs (KDE 4.2?) + KConfigGroup group(KSharedConfig::openConfig("dolphinrc"), "NewTagDialog"); + saveDialogSize(group, KConfigBase::Persistent); +} + + +QSize NewTagDialog::sizeHint() const +{ + return QSize(400, 256); +} + +void NewTagDialog::slotLabelChanged( const QString& text ) +{ + enableButtonOk( !text.isEmpty() ); +} + + +Nepomuk::Tag NewTagDialog::createTag( QWidget* parent ) +{ + NewTagDialog dlg( parent ); + dlg.m_labelTitle->setText( i18nc( "@title:window", "Create New Tag" ) ); + dlg.m_labelTitle->setComment( i18nc( "@title:window subtitle to previous message", "with optional icon and description" ) ); + dlg.m_labelTitle->setPixmap( KIcon( "nepomuk" ).pixmap( 32, 32 ) ); + + dlg.m_editTagLabel->setFocus(); + + if ( dlg.exec() ) { + QString name = dlg.m_editTagLabel->text(); + QString comment = dlg.m_editTagComment->text(); + QString icon = dlg.m_buttonTagIcon->icon(); + + Nepomuk::Tag newTag( name ); + newTag.setLabel( name ); + newTag.addIdentifier( name ); + if ( !comment.isEmpty() ) { + newTag.setDescription( comment ); + } + if ( !icon.isEmpty() ) { + newTag.addSymbol( icon ); + } + return newTag; + } + else { + return Nepomuk::Tag(); + } +} + +#include "newtagdialog.moc" diff --git a/src/panels/information/newtagdialog.h b/src/panels/information/newtagdialog.h new file mode 100644 index 000000000..b11cd1611 --- /dev/null +++ b/src/panels/information/newtagdialog.h @@ -0,0 +1,47 @@ +/* + Copyright (C) 2008 by Sebastian Trueg + + 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. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef _NEW_TAG_DIALOG_H_ +#define _NEW_TAG_DIALOG_H_ + +#include +#include "ui_newtagdialog.h" + +namespace Nepomuk { + class Tag; +} + +class NewTagDialog : public KDialog, public Ui_NewTagDialog +{ + Q_OBJECT + +public: + ~NewTagDialog(); + + virtual QSize sizeHint() const; + + static Nepomuk::Tag createTag( QWidget* parent = 0 ); + +private Q_SLOTS: + void slotLabelChanged( const QString& text ); + +private: + NewTagDialog( QWidget* parent = 0 ); +}; + +#endif diff --git a/src/panels/information/newtagdialog.ui b/src/panels/information/newtagdialog.ui new file mode 100644 index 000000000..d9bd666b5 --- /dev/null +++ b/src/panels/information/newtagdialog.ui @@ -0,0 +1,110 @@ + + NewTagDialog + + + + 0 + 0 + 390 + 149 + + + + + + + + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 5 + + + + + + + + Name: + + + + + + + + + + + + + 0 + 0 + + + + + + + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 10 + + + + + + + + Detailed description (optional): + + + + + + + + + + + KIconButton + QPushButton +

kicondialog.h
+ + + KLineEdit + QLineEdit +
klineedit.h
+
+ + KTitleWidget + QWidget +
ktitlewidget.h
+
+ + + + diff --git a/src/panels/information/resourcetaggingwidget.cpp b/src/panels/information/resourcetaggingwidget.cpp new file mode 100644 index 000000000..3a4da3ea9 --- /dev/null +++ b/src/panels/information/resourcetaggingwidget.cpp @@ -0,0 +1,193 @@ +/* + This file is part of the Nepomuk KDE project. + Copyright (C) 2007 Sebastian Trueg + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + */ + +#include "resourcetaggingwidget.h" +#include "tagcloud.h" +#include "taggingpopup.h" +#include "nepomukmassupdatejob.h" + +#include +#include +#include +#include +#include + +#include + +namespace Nepomuk { + inline uint qHash( const Tag& res ) + { + return qHash( res.resourceUri().toString() ); + } +} + + +class Nepomuk::ResourceTaggingWidget::Private +{ +public: + QList resources; + + TagCloud* resourceTagCloud; + TaggingPopup* popup; + + QList resourceTags; + + void showTaggingPopup( const QPoint& ); + void _k_slotShowTaggingPopup(); + void _k_metadataUpdateDone(); + static QList intersectTags( const QList& ); + + ResourceTaggingWidget* q; +}; + + +void Nepomuk::ResourceTaggingWidget::Private::showTaggingPopup( const QPoint& pos ) +{ + popup->showAllTags(); + resourceTags = intersectTags( resources ); + Q_FOREACH( const Tag &tag, resourceTags ) { + popup->setTagSelected( tag, true ); + } + + popup->exec( pos ); + + MassUpdateJob* job = MassUpdateJob::tagResources( resources, resourceTags ); + connect( job, SIGNAL( result( KJob* ) ), + q, SLOT( _k_metadataUpdateDone() ) ); + q->setEnabled( false ); // no updates during execution + job->start(); + + resourceTagCloud->showTags( resourceTags ); +} + + +void Nepomuk::ResourceTaggingWidget::Private::_k_slotShowTaggingPopup() +{ + showTaggingPopup( QCursor::pos() ); +} + + +void Nepomuk::ResourceTaggingWidget::Private::_k_metadataUpdateDone() +{ + q->setEnabled( true ); +} + + +QList Nepomuk::ResourceTaggingWidget::Private::intersectTags( const QList& res ) +{ + if ( res.count() == 1 ) { + return res.first().tags(); + } + else if ( !res.isEmpty() ) { + // determine the tags used for all resources + QSet tags = QSet::fromList( res.first().tags() ); + QList::const_iterator it = res.begin(); + for ( ++it; it != res.end(); ++it ) { + tags.intersect( QSet::fromList( (*it).tags() ) ); + } + return tags.values(); + } + else { + return QList(); + } +} + + +Nepomuk::ResourceTaggingWidget::ResourceTaggingWidget( QWidget* parent ) + : QWidget( parent ), + d( new Private() ) +{ + d->q = this; + + QVBoxLayout* layout = new QVBoxLayout( this ); + layout->setMargin( 0 ); + d->resourceTagCloud = new TagCloud( this ); + layout->addWidget( d->resourceTagCloud ); + QLabel* changeTagsLabel = new QLabel( "

" + i18nc( "@label", "Change Tags..." ) + "", this ); + connect( changeTagsLabel, SIGNAL( linkActivated( const QString ) ), + this, SLOT( _k_slotShowTaggingPopup() ) ); + layout->addWidget( changeTagsLabel ); + + // the popup tag cloud + d->popup = new TaggingPopup; + d->popup->setSelectionEnabled( true ); + d->popup->setNewTagButtonEnabled( true ); + + connect( d->popup, SIGNAL( tagToggled( const Nepomuk::Tag&, bool ) ), + this, SLOT( slotTagToggled( const Nepomuk::Tag&, bool ) ) ); + connect( d->popup, SIGNAL( tagAdded( const Nepomuk::Tag& ) ), + this, SLOT( slotTagAdded( const Nepomuk::Tag& ) ) ); + + connect( d->resourceTagCloud, SIGNAL( tagClicked( const Nepomuk::Tag& ) ), + this, SIGNAL( tagClicked( const Nepomuk::Tag& ) ) ); +} + + +Nepomuk::ResourceTaggingWidget::~ResourceTaggingWidget() +{ + delete d->popup; + delete d; +} + + +void Nepomuk::ResourceTaggingWidget::setResource( const Nepomuk::Resource& res ) +{ + setResources( QList() << res ); +} + + +void Nepomuk::ResourceTaggingWidget::setResources( const QList& resList ) +{ + d->resources = resList; + d->resourceTagCloud->showTags( d->intersectTags( resList ) ); +} + + +void Nepomuk::ResourceTaggingWidget::slotTagToggled( const Nepomuk::Tag& tag, bool enabled ) +{ + if ( enabled ) { + d->resourceTags.append( tag ); + } + else { + d->resourceTags.removeAll( tag ); + } + d->popup->hide(); +} + + +void Nepomuk::ResourceTaggingWidget::slotTagAdded( const Nepomuk::Tag& tag ) +{ + // assign it right away + d->resourceTags.append( tag ); +// d->resource.addTag( tag ); +} + + +void Nepomuk::ResourceTaggingWidget::contextMenuEvent( QContextMenuEvent* e ) +{ + d->showTaggingPopup( e->globalPos() ); +} + + +void Nepomuk::ResourceTaggingWidget::showTagPopup( const QPoint& pos ) +{ + d->showTaggingPopup( pos ); +} + +#include "resourcetaggingwidget.moc" diff --git a/src/panels/information/resourcetaggingwidget.h b/src/panels/information/resourcetaggingwidget.h new file mode 100644 index 000000000..4ddcea881 --- /dev/null +++ b/src/panels/information/resourcetaggingwidget.h @@ -0,0 +1,63 @@ +/* + This file is part of the Nepomuk KDE project. + Copyright (C) 2007 Sebastian Trueg + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + */ + +#ifndef _NEPOMUK_RESOURCE_TAGGING_WIDGET_H_ +#define _NEPOMUK_RESOURCE_TAGGING_WIDGET_H_ + +#include + +#include + +class QEvent; +class QContextMenuEvent; + +namespace Nepomuk { + class ResourceTaggingWidget : public QWidget + { + Q_OBJECT + + public: + ResourceTaggingWidget( QWidget* parent = 0 ); + ~ResourceTaggingWidget(); + + Q_SIGNALS: + void tagClicked( const Nepomuk::Tag& tag ); + + public Q_SLOTS: + void setResource( const Nepomuk::Resource& ); + void setResources( const QList& ); + void showTagPopup( const QPoint& pos ); + + private Q_SLOTS: + void slotTagToggled( const Nepomuk::Tag& tag, bool enabled ); + void slotTagAdded( const Nepomuk::Tag& tag ); + + protected: + void contextMenuEvent( QContextMenuEvent* e ); + + private: + class Private; + Private* const d; + + Q_PRIVATE_SLOT( d, void _k_slotShowTaggingPopup() ) + Q_PRIVATE_SLOT( d, void _k_metadataUpdateDone() ) + }; +} + +#endif diff --git a/src/panels/information/tagcloud.cpp b/src/panels/information/tagcloud.cpp new file mode 100644 index 000000000..0074d1796 --- /dev/null +++ b/src/panels/information/tagcloud.cpp @@ -0,0 +1,1005 @@ +/* + This file is part of the Nepomuk KDE project. + Copyright (C) 2007 Sebastian Trueg + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + */ + +#include "tagcloud.h" +#include "newtagdialog.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include + +#include + + +namespace { + const int s_hSpacing = 10; + const int s_vSpacing = 5; + + class TagNode { + public: + TagNode() + : weight( 0 ), + selected( false ) { + } + + // fixed info + Nepomuk::Tag tag; + int weight; + + // misc + bool selected; + + // info generated by rebuildCloud + QFont font; + QRect rect; + QRect zoomedRect; + QString text; + }; + + bool tagNodeNameLessThan( const TagNode& n1, const TagNode& n2 ) { + return n1.text < n2.text; + } + + bool tagNodeWeightLessThan( const TagNode& n1, const TagNode& n2 ) { + return n1.weight < n2.weight; + } + + int rowLength( const QList& row ) { + int rowLen = 0; + for ( int j = 0; j < row.count(); ++j ) { + rowLen += row[j]->rect.width(); + if ( j < row.count()-1 ) { + rowLen += s_hSpacing; + } + } + return rowLen; + } + + int rowHeight( const QList& row ) { + int h = 0; + for ( int j = 0; j < row.count(); ++j ) { + h = qMax( row[j]->rect.height(), h ); + } + return h; + } + + QSize cloudSize( const QList >& rows ) { + int w = 0; + int h = 0; + for ( int i = 0; i < rows.count(); ++i ) { + w = qMax( w, rowLength( rows[i] ) ); + h += rowHeight( rows[i] ); + if ( i < rows.count()-1 ) { + h += s_vSpacing; + } + } + return QSize( w, h ); + } +} + + +class Nepomuk::TagCloud::Private +{ +public: + Private( TagCloud* parent ) + : maxFontSize( 0 ), + minFontSize( 0 ), + maxNumberDisplayedTags( 0 ), + selectionEnabled( false ), + newTagButtonEnabled( false ), + alignment( Qt::AlignCenter ), + sorting( SortAlpabetically ), + zoomEnabled( true ), + showAllTags( false ), + customNewTagAction( 0 ), + hoverTag( 0 ), + cachedHfwWidth( -1 ), + m_parent( parent ) { + newTagNode.text = i18nc( "@label", "New Tag..." ); + } + + int maxFontSize; + int minFontSize; + int maxNumberDisplayedTags; + bool selectionEnabled; + bool newTagButtonEnabled; + Qt::Alignment alignment; + Sorting sorting; + bool zoomEnabled; + + // The resource whose tags we are showing + // invalid if we show all tags or a selection + KUrl resource; + bool showAllTags; + + // the actual nodes + QList nodes; + + // just a helper structure for speeding up things + QList > rows; + + TagNode newTagNode; + QAction* customNewTagAction; + + TagNode* hoverTag; + + QMatrix zoomMatrix; + + QSize cachedSizeHint; + int cachedHfwWidth; + int cachedHfwHeight; + + void invalidateCachedValues() { + cachedSizeHint = QSize(); + cachedHfwWidth = -1; + } + + int getMinFontSize() const; + int getMaxFontSize() const; + void updateNodeWeights(); + void updateNodeFonts(); + void sortNodes(); + void rebuildCloud(); + TagNode* tagAt( const QPoint& pos ); + TagNode* findTagInRow( const QList& row, const QPoint& pos ); + TagNode* nodeForTag( const Tag& tag ); + int calculateWeight( const Nepomuk::Tag& tag ); + +private: + TagCloud* m_parent; +}; + + +int Nepomuk::TagCloud::Private::getMinFontSize() const +{ + return minFontSize > 0 ? minFontSize : ( 8 * m_parent->font().pointSize() / 10 ); +} + + +int Nepomuk::TagCloud::Private::getMaxFontSize() const +{ + return maxFontSize > 0 ? maxFontSize : ( 22 * m_parent->font().pointSize() / 10 ); +} + + +int Nepomuk::TagCloud::Private::calculateWeight( const Nepomuk::Tag& tag ) +{ + // stupid SPARQL has no functions such as count! + Soprano::QueryResultIterator it + = ResourceManager::instance()->mainModel()->executeQuery( QString( "select ?r where { ?r <%1> <%2> . }" ) + .arg( Soprano::Vocabulary::NAO::hasTag().toString() ) + .arg( QString::fromAscii( tag.resourceUri().toEncoded() ) ), + Soprano::Query::QueryLanguageSparql ); + int w = 0; + while ( it.next() ) { + ++w; + } + return w; +} + + +void Nepomuk::TagCloud::Private::updateNodeWeights() +{ + bool changedWeights = false; + for ( QList::iterator it = nodes.begin(); + it != nodes.end(); ++it ) { + TagNode& node = *it; + int w = calculateWeight( node.tag ); + if ( w != node.weight ) { + node.weight = w; + changedWeights = true; + } + } + if ( changedWeights ) { + updateNodeFonts(); + } +} + + +void Nepomuk::TagCloud::Private::updateNodeFonts() +{ + int maxWeight = 0; + int minWeight = 0; + for ( QList::iterator it = nodes.begin(); + it != nodes.end(); ++it ) { + TagNode& node = *it; + minWeight = qMin( minWeight, node.weight ); + maxWeight = qMax( maxWeight, node.weight ); + } + + // calculate font sizes + // ---------------------------------------------- + int usedMinFontSize = getMinFontSize(); + int usedMaxFontSize = getMaxFontSize(); + for ( QList::iterator it = nodes.begin(); + it != nodes.end(); ++it ) { + TagNode& node = *it; + double normalizedWeight = (double)(node.weight - minWeight) / (double)qMax(maxWeight - minWeight, 1); + node.font = m_parent->font(); + node.font.setPointSize( usedMinFontSize + (int)((double)(usedMaxFontSize-usedMinFontSize) * normalizedWeight) ); + if( normalizedWeight > 0.8 ) + node.font.setBold( true ); + } + + if ( newTagButtonEnabled ) { + newTagNode.font = m_parent->font(); + newTagNode.font.setPointSize( usedMinFontSize ); + newTagNode.font.setUnderline( true ); + } +} + + +void Nepomuk::TagCloud::Private::sortNodes() +{ + if ( sorting == SortAlpabetically ) { + qSort( nodes.begin(), nodes.end(), tagNodeNameLessThan ); + } + else if ( sorting == SortByWeight ) { + qSort( nodes.begin(), nodes.end(), tagNodeWeightLessThan ); + } + else if ( sorting == SortRandom ) { + KRandomSequence().randomize( nodes ); + } +} + + +void Nepomuk::TagCloud::Private::rebuildCloud() +{ + // - Always try to be quadratic + // - Always prefer to expand horizontally + // - If we cannot fit everything into m_parent->contentsRect(), zoom + // - If alignment & Qt::AlignJustify insert spaces between tags + + sortNodes(); + + QRect contentsRect = m_parent->contentsRect(); + + // initialize the nodes' sizes + // ---------------------------------------------- + for ( QList::iterator it = nodes.begin(); + it != nodes.end(); ++it ) { + TagNode& node = *it; + node.rect = QFontMetrics( node.font ).boundingRect( node.text ); + } + if ( newTagButtonEnabled ) { + newTagNode.rect = QFontMetrics( newTagNode.font ).boundingRect( customNewTagAction ? customNewTagAction->text() : newTagNode.text ); + } + + + // and position the nodes + // ---------------------------------------------- + rows.clear(); + if ( !nodes.isEmpty() || newTagButtonEnabled ) { + if ( 0 ) { // FIXME: make it configurable + QRect lineRect; + QRect totalRect; + QList row; + for ( QList::iterator it = nodes.begin(); + it != nodes.end(); /* We do increment it below */ ) { + TagNode& node = *it; + + int usedSpacing = row.isEmpty() ? 0 : s_hSpacing; + if ( lineRect.width() + usedSpacing + node.rect.width() <= contentsRect.width() ) { + node.rect.moveBottomLeft( QPoint( lineRect.right() + usedSpacing, lineRect.bottom() ) ); + QRect newLineRect = lineRect.united( node.rect ); + newLineRect.moveTopLeft( lineRect.topLeft() ); + lineRect = newLineRect; + row.append( &node ); + + // update all other nodes in this line + Q_FOREACH( TagNode* n, row ) { + n->rect.moveBottom( lineRect.bottom() - ( lineRect.height() - n->rect.height() )/2 ); + } + + ++it; + } + else { + rows.append( row ); + row.clear(); + int newLineTop = lineRect.bottom() + s_vSpacing; + lineRect = QRect(); + lineRect.moveTop( newLineTop ); + } + } + rows.append( row ); + } + else { + // initialize first row + rows.append( QList() ); + for ( QList::iterator it = nodes.begin(); + it != nodes.end(); ++it ) { + TagNode& node = *it; + rows.first().append( &node ); + } + if ( newTagButtonEnabled ) { + rows.first().append( &newTagNode ); + } + + // calculate the rows + QList > bestRows( rows ); + QSize size( rowLength( rows.first() ), rowHeight( rows.first() ) ); + QSize bestSize( size ); + while ( ( size.height() < size.width() || + size.width() > contentsRect.width() ) && + size.height() <= contentsRect.height() ) { + // find the longest row + int maxRow = 0; + int maxLen = 0; + for ( int i = 0; i < rows.count(); ++i ) { + int rowLen = rowLength( rows[i] ); + if ( rowLen > maxLen ) { + maxLen = rowLen; + maxRow = i; + } + } + + // move the last item from the longest row to the next row + TagNode* node = rows[maxRow].takeLast(); + if ( rows.count() <= maxRow+1 ) { + rows.append( QList() ); + } + rows[maxRow+1].prepend( node ); + + // update the size + size = cloudSize( rows ); + + if ( size.width() < bestSize.width() && + ( size.width() > size.height() || + bestSize.width() > contentsRect.width() ) && + size.height() <= contentsRect.height() ) { + bestSize = size; + bestRows = rows; + } + } + rows = bestRows; + + // position the tags + int y = 0; + for ( QList >::iterator rowIt = rows.begin(); rowIt != rows.end(); ++rowIt ) { + QList& row = *rowIt; + int h = rowHeight( row ); + int x = 0; + Q_FOREACH( TagNode* node, row ) { + node->rect.moveTop( y + ( h - node->rect.height() )/2 ); + node->rect.moveLeft( x ); + x += s_hSpacing + node->rect.width(); + } + y += h + s_vSpacing; + } + } + + + // let's see if we have to zoom + // ---------------------------------------------- + zoomMatrix = QMatrix(); + int w = contentsRect.width(); + if ( zoomEnabled ) { + for ( QList >::iterator rowIt = rows.begin(); rowIt != rows.end(); ++rowIt ) { + QList& row = *rowIt; + w = qMax( w, row.last()->rect.right() ); + } + if ( w > contentsRect.width() ) { + double zoomFactor = ( double )contentsRect.width() / ( double )w; + zoomMatrix.scale( zoomFactor, zoomFactor ); + } + } + + // force horizontal alignment + // ---------------------------------------------- + for ( QList >::iterator rowIt = rows.begin(); rowIt != rows.end(); ++rowIt ) { + QList& row = *rowIt; + int space = /*contentsRect.right()*/w - row.last()->rect.right(); + if ( alignment & ( Qt::AlignRight|Qt::AlignHCenter ) ) { + Q_FOREACH( TagNode* node, row ) { + node->rect.moveLeft( node->rect.left() + ( alignment & Qt::AlignRight ? space : space/2 ) ); + } + } + else if ( alignment & Qt::AlignJustify && row.count() > 1 ) { + space /= ( row.count()-1 ); + int i = 0; + Q_FOREACH( TagNode* node, row ) { + node->rect.moveLeft( node->rect.left() + ( space * i++ ) ); + } + } + } + + // force vertical alignment + // ---------------------------------------------- + int verticalSpace = contentsRect.bottom() - rows.last().first()->rect.bottom(); + if ( alignment & ( Qt::AlignBottom|Qt::AlignVCenter ) ) { + for ( QList >::iterator rowIt = rows.begin(); rowIt != rows.end(); ++rowIt ) { + Q_FOREACH( TagNode* node, *rowIt ) { + node->rect.moveTop( node->rect.top() + ( alignment & Qt::AlignBottom ? verticalSpace : verticalSpace/2 ) ); + } + } + } + + for( QList::iterator it = nodes.begin(); it != nodes.end(); ++it ) { + it->zoomedRect = zoomMatrix.mapRect( it->rect ); + } + newTagNode.zoomedRect = zoomMatrix.mapRect( newTagNode.rect ); + } + + m_parent->updateGeometry(); + m_parent->update(); +} + + +// binary search in row +TagNode* Nepomuk::TagCloud::Private::findTagInRow( const QList& row, const QPoint& pos ) +{ + int x = m_parent->width() ? row.count() * pos.x() / m_parent->width() : 0; + + int i = 0; + while ( 1 ) { + if ( x-i >= 0 && x-i < row.count() && row[x-i]->zoomedRect.contains( pos ) ) { + return row[x-i]; + } + else if ( x+i >= 0 && x+i < row.count() && row[x+i]->zoomedRect.contains( pos ) ) { + return row[x+i]; + } + if ( x-i < 0 && x+i >= row.count() ) { + return 0; + } + ++i; + } + return 0; +} + + +// binary search in cloud +TagNode* Nepomuk::TagCloud::Private::tagAt( const QPoint& pos ) +{ + int y = m_parent->height() ? rows.count() * pos.y() / m_parent->height() : 0; + + int i = 0; + while ( 1 ) { + if ( y-i >= 0 && y-i < rows.count() ) { + if ( TagNode* node = findTagInRow( rows[y-i], pos ) ) { + return node; + } + } + if ( y+i >= 0 && y+i < rows.count() ) { + if ( TagNode* node = findTagInRow( rows[y+i], pos ) ) { + return node; + } + } + if ( y-i < 0 && y+i >= rows.count() ) { + return 0; + } + ++i; + } + return 0; +} + + +TagNode* Nepomuk::TagCloud::Private::nodeForTag( const Tag& tag ) +{ + for ( QList::iterator it = nodes.begin(); + it != nodes.end(); ++it ) { + TagNode& node = *it; + if ( tag == node.tag ) { + return &node; + } + } + return 0; +} + + + +Nepomuk::TagCloud::TagCloud( QWidget* parent ) + : QFrame( parent ), + d( new Private(this) ) +{ + QSizePolicy policy( QSizePolicy::Preferred, + QSizePolicy::Preferred ); + policy.setHeightForWidth( true ); + setSizePolicy( policy ); + setMouseTracking( true ); + + // Since signals are delivered in no particular order + // our slot might be called before the resources are updated + // Then, we would use invalid cached data. + // By using queued connections this problem should be solved. + connect( ResourceManager::instance()->mainModel(), + SIGNAL( statementAdded( const Soprano::Statement& ) ), + this, + SLOT( slotStatementAdded( const Soprano::Statement& ) ), + Qt::QueuedConnection ); + connect( ResourceManager::instance()->mainModel(), + SIGNAL( statementRemoved( const Soprano::Statement& ) ), + this, + SLOT( slotStatementRemoved( const Soprano::Statement& ) ), + Qt::QueuedConnection ); +} + + +Nepomuk::TagCloud::~TagCloud() +{ + delete d; +} + + +void Nepomuk::TagCloud::setMaxFontSize( int size ) +{ + d->invalidateCachedValues(); + d->maxFontSize = size; + d->updateNodeFonts(); + d->rebuildCloud(); +} + + +void Nepomuk::TagCloud::setMinFontSize( int size ) +{ + d->invalidateCachedValues(); + d->minFontSize = size; + d->updateNodeFonts(); + d->rebuildCloud(); +} + + +void Nepomuk::TagCloud::setMaxNumberDisplayedTags( int n ) +{ + d->maxNumberDisplayedTags = n; + d->rebuildCloud(); +} + + +void Nepomuk::TagCloud::setSelectionEnabled( bool enabled ) +{ + d->selectionEnabled = enabled; + update(); +} + + +void Nepomuk::TagCloud::setNewTagButtonEnabled( bool enabled ) +{ + d->newTagButtonEnabled = enabled; + d->rebuildCloud(); +} + + +bool Nepomuk::TagCloud::zoomEnabled() const +{ + return d->zoomEnabled; +} + + +void Nepomuk::TagCloud::setZoomEnabled( bool zoom ) +{ + if ( d->zoomEnabled != zoom ) { + d->zoomEnabled = zoom; + d->rebuildCloud(); + } +} + + +void Nepomuk::TagCloud::setContextMenuEnabled( bool enabled ) +{ + Q_UNUSED(enabled); +} + + +void Nepomuk::TagCloud::setAlignment( Qt::Alignment alignment ) +{ + d->alignment = alignment; + d->rebuildCloud(); +} + + +void Nepomuk::TagCloud::setSorting( Sorting s ) +{ + d->invalidateCachedValues(); + d->sorting = s; + d->rebuildCloud(); +} + + +void Nepomuk::TagCloud::showAllTags() +{ + showTags( Nepomuk::Tag::allTags() ); + d->showAllTags = true; +} + + +void Nepomuk::TagCloud::showResourceTags( const Resource& resource ) +{ + showTags( resource.tags() ); + d->resource = resource.uri(); +} + + +void Nepomuk::TagCloud::showTags( const QList& tags ) +{ + d->resource = QUrl(); + d->showAllTags = false; + d->invalidateCachedValues(); + d->nodes.clear(); + Q_FOREACH( const Tag &tag, tags ) { + TagNode node; + node.tag = tag; + node.weight = d->calculateWeight( tag ); + node.text = node.tag.genericLabel(); + + d->nodes.append( node ); + } + d->updateNodeFonts(); + d->rebuildCloud(); +} + + +void Nepomuk::TagCloud::setTagSelected( const Tag& tag, bool selected ) +{ + if ( TagNode* node = d->nodeForTag( tag ) ) { + node->selected = selected; + if ( d->selectionEnabled ) { + update( node->zoomedRect ); + } + } +} + + +QSize Nepomuk::TagCloud::sizeHint() const +{ + // If we have tags d->rebuildCloud() has been called at least once, + // thus, we have proper rects (i.e. needed sizes) + + if ( !d->cachedSizeHint.isValid() ) { + QList > rows; + rows.append( QList() ); + for ( QList::iterator it = d->nodes.begin(); + it != d->nodes.end(); ++it ) { + TagNode& node = *it; + rows.first().append( &node ); + } + if ( d->newTagButtonEnabled ) { + rows.first().append( &d->newTagNode ); + } + + QSize size( rowLength( rows.first() ), rowHeight( rows.first() ) ); + QSize bestSize( size ); + while ( size.height() < size.width() ) { + // find the longest row + int maxRow = 0; + int maxLen = 0; + for ( int i = 0; i < rows.count(); ++i ) { + int rowLen = rowLength( rows[i] ); + if ( rowLen > maxLen ) { + maxLen = rowLen; + maxRow = i; + } + } + + // move the last item from the longest row to the next row + TagNode* node = rows[maxRow].takeLast(); + if ( rows.count() <= maxRow+1 ) { + rows.append( QList() ); + } + rows[maxRow+1].prepend( node ); + + // update the size + size = cloudSize( rows ); + + if ( size.width() < bestSize.width() && + size.width() > size.height() ) { + bestSize = size; + } + } + + d->cachedSizeHint = QSize( bestSize.width() + frameWidth()*2, + bestSize.height() + frameWidth()*2 ); + } + + return d->cachedSizeHint; +} + + +QSize Nepomuk::TagCloud::minimumSizeHint() const +{ + return QFrame::minimumSizeHint(); + // If we have tags d->rebuildCloud() has been called at least once, + // thus, we have proper rects (i.e. needed sizes) + if ( d->nodes.isEmpty() && !d->newTagButtonEnabled ) { + return QSize( fontMetrics().width( i18nc( "@label Indicator when no tags defined", "No Tags" ) ), fontMetrics().height() ); + } + else { + QSize size; + for ( QList::iterator it = d->nodes.begin(); + it != d->nodes.end(); ++it ) { + size.setWidth( qMax( size.width(), ( *it ).rect.width() ) ); + size.setHeight( qMax( size.height(), ( *it ).rect.height() ) ); + } + if ( d->newTagButtonEnabled ) { + size.setWidth( qMax( size.width(), d->newTagNode.rect.width() ) ); + size.setHeight( qMax( size.height(), d->newTagNode.rect.height() ) ); + } + size.setWidth( size.width() + frameWidth()*2 ); + size.setHeight( size.height() + frameWidth()*2 ); + return size; + } +} + + +int Nepomuk::TagCloud::heightForWidth( int contentsWidth ) const +{ + // If we have tags d->rebuildCloud() has been called at least once, + // thus, we have proper rects (i.e. needed sizes) + + if ( d->cachedHfwWidth != contentsWidth ) { + // have to keep in mind the frame + contentsWidth -= frameWidth()*2; + + QList allNodes; + for ( QList::iterator it = d->nodes.begin(); + it != d->nodes.end(); ++it ) { + TagNode& node = *it; + allNodes.append( &node ); + } + if ( d->newTagButtonEnabled ) { + allNodes.append( &d->newTagNode ); + } + + int h = 0; + bool newRow = true; + int rowW = 0; + int rowH = 0; + int maxW = 0; + for ( int i = 0; i < allNodes.count(); ++i ) { + int w = rowW; + if ( !newRow ) { + w += s_hSpacing; + } + newRow = false; + w += allNodes[i]->rect.width(); + if ( w <= contentsWidth ) { + rowH = qMax( rowH, allNodes[i]->rect.height() ); + rowW = w; + } + else { + if ( h > 0 ) { + h += s_vSpacing; + } + h += rowH; + rowH = allNodes[i]->rect.height(); + rowW = allNodes[i]->rect.width(); + } + maxW = qMax( maxW, rowW ); + } + if ( rowH > 0 ) { + h += s_vSpacing + rowH; + } + + d->cachedHfwWidth = contentsWidth; + d->cachedHfwHeight = h; + + // zooming + if ( maxW > contentsWidth ) { + d->cachedHfwHeight = d->cachedHfwHeight * contentsWidth / maxW; + } + } + + return d->cachedHfwHeight + frameWidth()*2; +} + + +void Nepomuk::TagCloud::resizeEvent( QResizeEvent* e ) +{ + QFrame::resizeEvent( e ); + d->rebuildCloud(); + update(); +} + + +void Nepomuk::TagCloud::paintEvent( QPaintEvent* e ) +{ + QFrame::paintEvent( e ); + + KStatefulBrush normalTextBrush( KColorScheme::View, KColorScheme::NormalText ); + KStatefulBrush activeTextBrush( KColorScheme::View, KColorScheme::VisitedText ); + KStatefulBrush hoverTextBrush( KColorScheme::View, KColorScheme::ActiveText ); + + QPainter p( this ); + QRegion paintRegion = e->region(); + + p.save(); + p.setMatrix( d->zoomMatrix ); + + for ( QList::iterator it = d->nodes.begin(); + it != d->nodes.end(); ++it ) { + TagNode& node = *it; + + if ( paintRegion.contains( node.zoomedRect ) ) { + p.setFont( node.font ); + + if ( &node == d->hoverTag ) { + p.setPen( hoverTextBrush.brush( this ).color() ); + } + else if ( d->selectionEnabled && node.selected ) { + p.setPen( activeTextBrush.brush( this ).color() ); + } + else { + p.setPen( normalTextBrush.brush( this ).color() ); + } + p.drawText( node.rect, Qt::AlignCenter, node.text ); + } + } + + if ( d->newTagButtonEnabled ) { + p.setFont( d->newTagNode.font ); + if ( &d->newTagNode == d->hoverTag ) { + p.setPen( hoverTextBrush.brush( this ).color() ); + } + else { + p.setPen( normalTextBrush.brush( this ).color() ); + } + p.drawText( d->newTagNode.rect, Qt::AlignCenter, d->customNewTagAction ? d->customNewTagAction->text() : d->newTagNode.text ); + } + + p.restore(); +} + + +void Nepomuk::TagCloud::mousePressEvent( QMouseEvent* e ) +{ + if ( e->button() == Qt::LeftButton ) { + if ( TagNode* node = d->tagAt( e->pos() ) ) { + kDebug() << "clicked" << node->text; + if ( node == &d->newTagNode ) { + if ( d->customNewTagAction ) { + d->customNewTagAction->trigger(); + } + else { + // FIXME: nicer gui + Tag newTag = NewTagDialog::createTag( this ); + if ( newTag.isValid() ) { + emit tagAdded( newTag ); + } + } + } + else { + emit tagClicked( node->tag ); + if ( d->selectionEnabled ) { + kDebug() << "Toggleing tag" << node->text; + node->selected = !node->selected; + emit tagToggled( node->tag, node->selected ); + update( node->zoomedRect ); + } + } + } + } +} + + +void Nepomuk::TagCloud::mouseMoveEvent( QMouseEvent* e ) +{ + if ( e->buttons() == Qt::NoButton ) { + + TagNode* oldHoverTag = d->hoverTag; + + if ( ( d->hoverTag = d->tagAt( e->pos() ) ) && + !d->selectionEnabled ) { + setCursor( Qt::PointingHandCursor ); + } + else if ( d->newTagButtonEnabled && + d->newTagNode.zoomedRect.contains( e->pos() ) ) { + d->hoverTag = &d->newTagNode; + setCursor( Qt::PointingHandCursor ); + } + else { + unsetCursor(); + } + + if ( oldHoverTag || d->hoverTag ) { + QRect updateRect; + if ( d->hoverTag ) + updateRect = updateRect.united( d->hoverTag->zoomedRect ); + if ( oldHoverTag ) + updateRect = updateRect.united( oldHoverTag->zoomedRect ); + + update( updateRect ); + } + } +} + + +void Nepomuk::TagCloud::leaveEvent( QEvent* ) +{ + unsetCursor(); + if ( d->hoverTag ) { + QRect updateRect = d->hoverTag->zoomedRect; + d->hoverTag = 0; + update( updateRect ); + } +} + + +void Nepomuk::TagCloud::slotStatementAdded( const Soprano::Statement& s ) +{ + if ( s.predicate().uri() == Soprano::Vocabulary::RDF::type() && + s.object().uri() == Nepomuk::Tag::resourceTypeUri() ) { + // new tag created + if ( d->showAllTags ) { + showAllTags(); + } + } + else if ( s.predicate().uri() == Nepomuk::Resource::tagUri() ) { + if ( s.subject().uri() == d->resource ) { + showResourceTags( d->resource ); + } + else { + // weights might have changed + d->updateNodeWeights(); + d->rebuildCloud(); + } + } +} + + +void Nepomuk::TagCloud::slotStatementRemoved( const Soprano::Statement& s ) +{ + // FIXME: In theory might contain empty nodes as wildcards + + if ( s.predicate().uri() == Nepomuk::Resource::tagUri() ) { + if ( d->resource.isValid() && + d->resource == s.subject().uri() ) { + showResourceTags( d->resource ); + } + else { + // weights might have changed + d->updateNodeWeights(); + d->rebuildCloud(); + } + } + else if ( s.predicate().uri() == Soprano::Vocabulary::RDF::type() && + s.object().uri() == Nepomuk::Tag::resourceTypeUri() ) { + // tag deleted + if ( d->showAllTags ) { + showAllTags(); + } + } +} + + +void Nepomuk::TagCloud::setCustomNewTagAction( QAction* action ) +{ + d->customNewTagAction = action; + setNewTagButtonEnabled( action != 0 ); +} + +#include "tagcloud.moc" diff --git a/src/panels/information/tagcloud.h b/src/panels/information/tagcloud.h new file mode 100644 index 000000000..9710ca9b7 --- /dev/null +++ b/src/panels/information/tagcloud.h @@ -0,0 +1,142 @@ +/* + This file is part of the Nepomuk KDE project. + Copyright (C) 2007 Sebastian Trueg + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + */ + +#ifndef _NEPOMUK_TAG_CLOUD_H_ +#define _NEPOMUK_TAG_CLOUD_H_ + +#include +#include + +#include + +#include + +class QResizeEvent; +class QPaintEvent; +class QMouseEvent; +class QEvent; + +namespace Nepomuk { + class TagCloud : public QFrame + { + Q_OBJECT + + public: + TagCloud( QWidget* parent = 0 ); + ~TagCloud(); + + enum Sorting { + SortAlpabetically, + SortByWeight, + SortRandom + }; + + int heightForWidth( int w ) const; + QSize sizeHint() const; + QSize minimumSizeHint() const; + + bool zoomEnabled() const; + + public Q_SLOTS: + /** + * Set the maximum used font size. The default is 0 + * which means to calculate proper values from the KDE + * defaults. + */ + void setMaxFontSize( int size ); + + /** + * Set the minimum used font size. The default is 0 + * which means to calculate proper values from the KDE + * defaults. + */ + void setMinFontSize( int size ); + + /** + * Set the maximum number of displayed tags. The default is 0 + * which means to display all tags. + * + * NOT IMPLEMENTED YET + */ + void setMaxNumberDisplayedTags( int n ); + + /** + * Allow selection of tags, i.e. enabling and disabling of tags. + */ + void setSelectionEnabled( bool enabled ); + + void setNewTagButtonEnabled( bool enabled ); + void setContextMenuEnabled( bool enabled ); + void setAlignment( Qt::Alignment alignment ); + + void setZoomEnabled( bool zoom ); + + /** + * Default: SortAlpabetically + */ + void setSorting( Sorting ); + + /** + * Will reset tags set via showTags() + */ + void showAllTags(); + + /** + * Set the tags to be shown in the tag cloud. + * If the new tag button is enabled (setEnableNewTagButton()) + * new tags will automatically be added to the list of shown tags. + */ + void showTags( const QList& tags ); + + void showResourceTags( const Resource& resource ); + + /** + * Select or deselect a tag. This does only make sense + * if selection is enabled and \p tag is actually + * displayed. + * + * \sa setSelectionEnabled + */ + void setTagSelected( const Tag& tag, bool selected ); + + void setCustomNewTagAction( QAction* action ); + + Q_SIGNALS: + void tagClicked( const Nepomuk::Tag& tag ); + void tagAdded( const Nepomuk::Tag& tag ); + void tagToggled( const Nepomuk::Tag& tag, bool enabled ); + + protected: + void resizeEvent( QResizeEvent* e ); + void paintEvent( QPaintEvent* e ); + void mousePressEvent( QMouseEvent* ); + void mouseMoveEvent( QMouseEvent* ); + void leaveEvent( QEvent* ); + + private Q_SLOTS: + void slotStatementAdded( const Soprano::Statement& s ); + void slotStatementRemoved( const Soprano::Statement& s ); + + private: + class Private; + Private* const d; + }; +} + +#endif diff --git a/src/panels/information/taggingpopup.cpp b/src/panels/information/taggingpopup.cpp new file mode 100644 index 000000000..3e59c80d1 --- /dev/null +++ b/src/panels/information/taggingpopup.cpp @@ -0,0 +1,147 @@ +/* + This file is part of the Nepomuk KDE project. + Copyright (C) 2007 Sebastian Trueg + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + */ + +#include "taggingpopup.h" + +#include +#include +#include +#include +#include + +#include +#include + + +class Nepomuk::TaggingPopup::Private +{ +public: + Private( TaggingPopup* parent ) + : eventLoop( 0 ), + m_parent( parent ) { + } + + QEventLoop* eventLoop; + QPoint popupPos; + + QRect geometryForPopupPos( const QPoint& p ) { + QSize size = m_parent->sizeHint(); + + // we want a little margin + const int margin = KDialog::marginHint(); + size.setHeight( size.height() + margin*2 ); + size.setWidth( size.width() + margin*2 ); + + QRect screen = QApplication::desktop()->screenGeometry( QApplication::desktop()->screenNumber( p ) ); + + // calculate popup position + QPoint pos( p.x() - size.width()/2, p.y() - size.height()/2 ); + + // ensure we do not leave the desktop + if ( pos.x() + size.width() > screen.right() ) { + pos.setX( screen.right() - size.width() ); + } + else if ( pos.x() < screen.left() ) { + pos.setX( screen.left() ); + } + + if ( pos.y() + size.height() > screen.bottom() ) { + pos.setY( screen.bottom() - size.height() ); + } + else if ( pos.y() < screen.top() ) { + pos.setY( screen.top() ); + } + + return QRect( pos, size ); + } + +private: + TaggingPopup* m_parent; +}; + + +Nepomuk::TaggingPopup::TaggingPopup( QWidget* parent ) + : TagCloud( parent ), + d( new Private( this ) ) +{ + setFrameStyle( QFrame::Box|QFrame::Plain ); + setWindowFlags( Qt::Popup ); +} + + +Nepomuk::TaggingPopup::~TaggingPopup() +{ + delete d; +} + + +void Nepomuk::TaggingPopup::popup( const QPoint& p ) +{ + setGeometry( d->geometryForPopupPos( p ) ); + d->popupPos = p; + + show(); +} + + +void Nepomuk::TaggingPopup::exec( const QPoint& pos ) +{ + QEventLoop eventLoop; + d->eventLoop = &eventLoop; + popup( pos ); + + QPointer guard = this; + (void) eventLoop.exec(); + if ( !guard.isNull() ) + d->eventLoop = 0; +} + + +void Nepomuk::TaggingPopup::mousePressEvent( QMouseEvent* e ) +{ + if ( !rect().contains( e->pos() ) ) { + hide(); + } + else { + TagCloud::mousePressEvent( e ); + } +} + + +void Nepomuk::TaggingPopup::hideEvent( QHideEvent* e ) +{ + Q_UNUSED( e ); + if ( d->eventLoop ) { + d->eventLoop->exit(); + } +} + + +bool Nepomuk::TaggingPopup::event( QEvent* e ) +{ + if ( e->type() == QEvent::LayoutRequest ) { + if ( isVisible() ) { + setGeometry( d->geometryForPopupPos( d->popupPos ) ); + return true; + } + } + + return TagCloud::event( e ); +} + diff --git a/src/panels/information/taggingpopup.h b/src/panels/information/taggingpopup.h new file mode 100644 index 000000000..99cee701c --- /dev/null +++ b/src/panels/information/taggingpopup.h @@ -0,0 +1,50 @@ +/* + This file is part of the Nepomuk KDE project. + Copyright (C) 2007 Sebastian Trueg + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + */ + +#ifndef _NEPOMUK_TAGGING_POPUP_H_ +#define _NEPOMUK_TAGGING_POPUP_H_ + +#include "tagcloud.h" + +class QMouseEvent; +class QHideEvent; + +namespace Nepomuk { + class TaggingPopup : public TagCloud + { + public: + TaggingPopup( QWidget* parent = 0 ); + ~TaggingPopup(); + + void popup( const QPoint& pos ); + void exec( const QPoint& pos ); + + bool event( QEvent* e ); + + protected: + void mousePressEvent( QMouseEvent* e ); + void hideEvent( QHideEvent* e ); + + private: + class Private; + Private* const d; + }; +} + +#endif diff --git a/src/panels/places/dolphinfileplacesview.cpp b/src/panels/places/dolphinfileplacesview.cpp new file mode 100644 index 000000000..df3e6fd87 --- /dev/null +++ b/src/panels/places/dolphinfileplacesview.cpp @@ -0,0 +1,56 @@ +/*************************************************************************** + * Copyright (C) 2008 by Peter Penz * + * * + * 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 of the License, 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. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#include "dolphinfileplacesview.h" +#include "draganddrophelper.h" +#include +#include + +DolphinFilePlacesView::DolphinFilePlacesView(QWidget* parent) : + KFilePlacesView(parent), + m_mouseButtons(Qt::NoButton) +{ + setDropOnPlaceEnabled(true); + connect(this, SIGNAL(urlsDropped(const KUrl&, QDropEvent*, QWidget*)), + this, SLOT(slotUrlsDropped(const KUrl&, QDropEvent*, QWidget*))); + connect(this, SIGNAL(urlChanged(const KUrl&)), + this, SLOT(emitExtendedUrlChangedSignal(const KUrl&))); +} + +DolphinFilePlacesView::~DolphinFilePlacesView() +{ +} + +void DolphinFilePlacesView::mousePressEvent(QMouseEvent* event) +{ + m_mouseButtons = event->buttons(); + KFilePlacesView::mousePressEvent(event); +} + +void DolphinFilePlacesView::slotUrlsDropped(const KUrl& dest, QDropEvent* event, QWidget* parent) +{ + DragAndDropHelper::instance().dropUrls(KFileItem(), dest, event, parent); +} + +void DolphinFilePlacesView::emitExtendedUrlChangedSignal(const KUrl& url) +{ + emit urlChanged(url, m_mouseButtons); +} + +#include "dolphinfileplacesview.moc" diff --git a/src/panels/places/dolphinfileplacesview.h b/src/panels/places/dolphinfileplacesview.h new file mode 100644 index 000000000..46d574606 --- /dev/null +++ b/src/panels/places/dolphinfileplacesview.h @@ -0,0 +1,51 @@ +/*************************************************************************** + * Copyright (C) 2008 by Peter Penz * + * * + * 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 of the License, 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. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#ifndef DOLPHINFILEPLACESVIEW_H +#define DOLPHINFILEPLACESVIEW_H + +#include + +/** + * @brief Combines bookmarks and mounted devices as list which is + * embedded as panel. + */ +class DolphinFilePlacesView : public KFilePlacesView +{ + Q_OBJECT + +public: + DolphinFilePlacesView(QWidget* parent); + virtual ~DolphinFilePlacesView(); + +signals: + void urlChanged(const KUrl& url, Qt::MouseButtons buttons); + +protected: + virtual void mousePressEvent(QMouseEvent* event); + +private slots: + void slotUrlsDropped(const KUrl& dest, QDropEvent* event, QWidget* parent); + void emitExtendedUrlChangedSignal(const KUrl& url); + +private: + Qt::MouseButtons m_mouseButtons; +}; + +#endif // DOLPHINFILEPLACESVIEW_H diff --git a/src/panels/sidebarpage.cpp b/src/panels/sidebarpage.cpp new file mode 100644 index 000000000..594f59f24 --- /dev/null +++ b/src/panels/sidebarpage.cpp @@ -0,0 +1,46 @@ +/*************************************************************************** + * Copyright (C) 2006 by Cvetoslav Ludmiloff * + * Copyright (C) 2006 by Peter Penz * + * * + * 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 of the License, 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. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#include "sidebarpage.h" +#include +#include +#include + +SidebarPage::SidebarPage(QWidget* parent) : + QWidget(parent), + m_url(KUrl()) +{ +} + +SidebarPage::~SidebarPage() +{ +} + +const KUrl& SidebarPage::url() const +{ + return m_url; +} + +void SidebarPage::setUrl(const KUrl& url) +{ + m_url = url; +} + +#include "sidebarpage.moc" diff --git a/src/panels/sidebarpage.h b/src/panels/sidebarpage.h new file mode 100644 index 000000000..20a44758e --- /dev/null +++ b/src/panels/sidebarpage.h @@ -0,0 +1,53 @@ +/*************************************************************************** + * Copyright (C) 2006 by Cvetoslav Ludmiloff * + * Copyright (C) 2006 by Peter Penz * + * * + * 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 of the License, 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. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#ifndef _SIDEBARPAGE_H_ +#define _SIDEBARPAGE_H_ + +#include +#include +#include + +/** + * @brief Base widget for all pages that can be embedded into the Sidebar. + */ +class SidebarPage : public QWidget +{ + Q_OBJECT + +public: + explicit SidebarPage(QWidget* parent = 0); + virtual ~SidebarPage(); + + /** Returns the current set URL of the active Dolphin view. */ + const KUrl& url() const; + +public slots: + /** + * This is invoked every time the folder being displayed in the + * active Dolphin view changes. + */ + virtual void setUrl(const KUrl& url); + +private: + KUrl m_url; +}; + +#endif // _SIDEBARPAGE_H_ diff --git a/src/panels/terminal/terminalsidebarpage.cpp b/src/panels/terminal/terminalsidebarpage.cpp new file mode 100644 index 000000000..4749e7714 --- /dev/null +++ b/src/panels/terminal/terminalsidebarpage.cpp @@ -0,0 +1,97 @@ +/*************************************************************************** + * Copyright (C) 2007 by Peter Penz * + * * + * 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 of the License, 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. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#include "terminalsidebarpage.h" + +#include +#include +#include +#include + +#include +#include + +TerminalSidebarPage::TerminalSidebarPage(QWidget* parent) : + SidebarPage(parent), + m_layout(0), + m_terminal(0), + m_terminalWidget(0) +{ + m_layout = new QVBoxLayout(this); + m_layout->setMargin(0); +} + +TerminalSidebarPage::~TerminalSidebarPage() +{ +} + +QSize TerminalSidebarPage::sizeHint() const +{ + QSize size = SidebarPage::sizeHint(); + size.setHeight(200); + return size; +} + +void TerminalSidebarPage::setUrl(const KUrl& url) +{ + if (!url.isValid() || (url == SidebarPage::url())) { + return; + } + + SidebarPage::setUrl(url); + if ((m_terminal != 0) && isVisible() && url.isLocalFile()) { + m_terminal->sendInput("cd " + KShell::quoteArg(url.path()) + '\n'); + } +} + +void TerminalSidebarPage::terminalExited() +{ + emit hideTerminalSidebarPage(); + + m_terminal = 0; +} + +void TerminalSidebarPage::showEvent(QShowEvent* event) +{ + if (event->spontaneous()) { + SidebarPage::showEvent(event); + return; + } + + if (m_terminal == 0) { + KPluginFactory* factory = KPluginLoader("libkonsolepart").factory(); + KParts::ReadOnlyPart* part = factory ? (factory->create(this)) : 0; + if (part != 0) { + connect(part, SIGNAL(destroyed(QObject*)), this, SLOT(terminalExited())); + m_terminalWidget = part->widget(); + m_layout->addWidget(m_terminalWidget); + m_terminal = qobject_cast(part); + m_terminal->showShellInDir(url().path()); + } + } + if (m_terminal != 0) { + m_terminal->sendInput("cd " + KShell::quoteArg(url().path()) + '\n'); + m_terminal->sendInput("clear\n"); + m_terminalWidget->setFocus(); + } + + SidebarPage::showEvent(event); +} + +#include "terminalsidebarpage.moc" diff --git a/src/panels/terminal/terminalsidebarpage.h b/src/panels/terminal/terminalsidebarpage.h new file mode 100644 index 000000000..4e8c40593 --- /dev/null +++ b/src/panels/terminal/terminalsidebarpage.h @@ -0,0 +1,62 @@ +/*************************************************************************** + * Copyright (C) 2007 by Peter Penz * + * * + * 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 of the License, 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. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#ifndef TERMINALSIDEBARPAGE_H +#define TERMINALSIDEBARPAGE_H + +#include + +class TerminalInterface; +class QVBoxLayout; +class QWidget; + +/** + * @brief Shows the terminal which is synchronized with the URL of the + * active view. + */ +class TerminalSidebarPage : public SidebarPage +{ + Q_OBJECT + +public: + TerminalSidebarPage(QWidget* parent = 0); + virtual ~TerminalSidebarPage(); + + /** @see QWidget::sizeHint() */ + virtual QSize sizeHint() const; + +public slots: + /** @see SidebarPage::setUrl(). */ + virtual void setUrl(const KUrl& url); + void terminalExited(); + +signals: + void hideTerminalSidebarPage(); + +protected: + /** @see QWidget::showEvent() */ + virtual void showEvent(QShowEvent* event); + +private: + QVBoxLayout* m_layout; + TerminalInterface* m_terminal; + QWidget* m_terminalWidget; +}; + +#endif // TERMINALSIDEBARPAGE_H diff --git a/src/settings/additionalinfodialog.cpp b/src/settings/additionalinfodialog.cpp new file mode 100644 index 000000000..2f735fffe --- /dev/null +++ b/src/settings/additionalinfodialog.cpp @@ -0,0 +1,102 @@ +/*************************************************************************** + * Copyright (C) 2007 by Peter Penz (peter.penz@gmx.at) * + * * + * 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 of the License, 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. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#include "additionalinfodialog.h" + +#include +#include + +#include + +AdditionalInfoDialog::AdditionalInfoDialog(QWidget* parent, + KFileItemDelegate::InformationList info) : + KDialog(parent), + m_info(info), + m_size(0), + m_date(0), + m_permissions(0), + m_owner(0), + m_group(0), + m_type(0) +{ + setCaption(i18nc("@title:window", "Additional Information")); + setButtons(Ok | Cancel); + setDefaultButton(Ok); + + KVBox* box = new KVBox(this); + + m_size = new QCheckBox(i18nc("@option:check Additional Information", "Size"), box); + m_date = new QCheckBox(i18nc("@option:check Additional Information", "Date"), box); + m_permissions = new QCheckBox(i18nc("@option:check Additional Information", "Permissions"), box); + m_owner = new QCheckBox(i18nc("@option:check Additional Information", "Owner"), box); + m_group = new QCheckBox(i18nc("@option:check Additional Information", "Group"), box); + m_type = new QCheckBox(i18nc("@option:check Additional Information", "Type"), box); + connect(this, SIGNAL(okClicked()), this, SLOT(slotOk())); + + m_size->setChecked(info.contains(KFileItemDelegate::Size)); + m_date->setChecked(info.contains(KFileItemDelegate::ModificationTime)); + m_permissions->setChecked(info.contains(KFileItemDelegate::Permissions)); + m_owner->setChecked(info.contains(KFileItemDelegate::Owner)); + m_group->setChecked(info.contains(KFileItemDelegate::OwnerAndGroup)); + m_type->setChecked(info.contains(KFileItemDelegate::FriendlyMimeType)); + + setMainWidget(box); + + const KConfigGroup dialogConfig(KSharedConfig::openConfig("dolphinrc"), + "AdditionalInfoDialog"); + restoreDialogSize(dialogConfig); +} + +AdditionalInfoDialog::~AdditionalInfoDialog() +{ + KConfigGroup dialogConfig(KSharedConfig::openConfig("dolphinrc"), + "AdditionalInfoDialog"); + saveDialogSize(dialogConfig, KConfigBase::Persistent); +} + +KFileItemDelegate::InformationList AdditionalInfoDialog::additionalInfo() const +{ + return m_info; +} + +void AdditionalInfoDialog::slotOk() +{ + m_info.clear(); + + if (m_size->isChecked()) { + m_info.append(KFileItemDelegate::Size); + } + if (m_date->isChecked()) { + m_info.append(KFileItemDelegate::ModificationTime); + } + if (m_permissions->isChecked()) { + m_info.append(KFileItemDelegate::Permissions); + } + if (m_owner->isChecked()) { + m_info.append(KFileItemDelegate::Owner); + } + if (m_group->isChecked()) { + m_info.append(KFileItemDelegate::OwnerAndGroup); + } + if (m_type->isChecked()) { + m_info.append(KFileItemDelegate::FriendlyMimeType); + } +} + +#include "additionalinfodialog.moc" diff --git a/src/settings/additionalinfodialog.h b/src/settings/additionalinfodialog.h new file mode 100644 index 000000000..9771960f0 --- /dev/null +++ b/src/settings/additionalinfodialog.h @@ -0,0 +1,53 @@ +/*************************************************************************** + * Copyright (C) 2007 by Peter Penz (peter.penz@gmx.at) * + * * + * 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 of the License, 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. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#ifndef ADDITIONALINFODIALOG_H +#define ADDITIONALINFODIALOG_H + +#include +#include + +class QCheckBox; + +/** + * @brief Dialog for changing the additional information properties of a directory. + */ +class AdditionalInfoDialog : public KDialog +{ + Q_OBJECT + +public: + explicit AdditionalInfoDialog(QWidget* parent, KFileItemDelegate::InformationList info); + virtual ~AdditionalInfoDialog(); + KFileItemDelegate::InformationList additionalInfo() const; + +private slots: + void slotOk(); + +private: + KFileItemDelegate::InformationList m_info; + QCheckBox* m_size; + QCheckBox* m_date; + QCheckBox* m_permissions; + QCheckBox* m_owner; + QCheckBox* m_group; + QCheckBox* m_type; +}; + +#endif diff --git a/src/settings/applyviewpropsjob.cpp b/src/settings/applyviewpropsjob.cpp new file mode 100644 index 000000000..9250226e9 --- /dev/null +++ b/src/settings/applyviewpropsjob.cpp @@ -0,0 +1,81 @@ +/*************************************************************************** + * Copyright (C) 2006 by Peter Penz * + * * + * The code is based on kdelibs/kio/directorysizejob.* * + * (C) 2006 by David Faure * + * * + * 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 of the License, 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. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#include "applyviewpropsjob.h" +#include "viewproperties.h" + +ApplyViewPropsJob::ApplyViewPropsJob(const KUrl& dir, + const ViewProperties& viewProps) : + KIO::Job(), + m_viewProps(0), + m_progress(0), + m_dir(dir) +{ + m_viewProps = new ViewProperties(dir); + m_viewProps->setViewMode(viewProps.viewMode()); + m_viewProps->setShowPreview(viewProps.showPreview()); + m_viewProps->setShowHiddenFiles(viewProps.showHiddenFiles()); + m_viewProps->setSorting(viewProps.sorting()); + m_viewProps->setSortOrder(viewProps.sortOrder()); + + KIO::ListJob* listJob = KIO::listRecursive(dir, KIO::HideProgressInfo); + connect(listJob, SIGNAL(entries(KIO::Job*, const KIO::UDSEntryList&)), + SLOT(slotEntries(KIO::Job*, const KIO::UDSEntryList&))); + addSubjob(listJob); +} + +ApplyViewPropsJob::~ApplyViewPropsJob() +{ + delete m_viewProps; // the properties are written by the destructor + m_viewProps = 0; +} + +void ApplyViewPropsJob::slotEntries(KIO::Job*, const KIO::UDSEntryList& list) +{ + KIO::UDSEntryList::ConstIterator it = list.begin(); + const KIO::UDSEntryList::ConstIterator end = list.end(); + foreach(const KIO::UDSEntry& entry, list) { + const QString name = entry.stringValue(KIO::UDSEntry::UDS_NAME); + if ((name != ".") && (name != "..") && entry.isDir()) { + ++m_progress; + + KUrl url(m_dir); + url.addPath(name); + + Q_ASSERT(m_viewProps != 0); + + ViewProperties props(url); + props.setDirProperties(*m_viewProps); + } + } +} + +void ApplyViewPropsJob::slotResult(KJob* job) +{ + if (job->error()) { + setError(job->error()); + setErrorText(job->errorText()); + } + emitResult(); +} + +#include "applyviewpropsjob.moc" diff --git a/src/settings/applyviewpropsjob.h b/src/settings/applyviewpropsjob.h new file mode 100644 index 000000000..da18af966 --- /dev/null +++ b/src/settings/applyviewpropsjob.h @@ -0,0 +1,83 @@ +/*************************************************************************** + * Copyright (C) 2006 by Peter Penz * + * * + * The code is based on kdelibs/kio/kio/directorysizejob.* * + * (C) 2006 by David Faure * + * * + * 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 of the License, 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. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#ifndef APPLYVIEWPROPSJOB_H +#define APPLYVIEWPROPSJOB_H + +#include +#include +#include + +class ViewProperties; + +/** + * @brief Applies view properties recursively to directories. + * + * Usage: + * \code + * KJob* job = new ApplyViewPropsJob(dir, viewProps); + * connect(job, SIGNAL(result(KJob*)), + * this, SLOT(slotResult(KJob*))); + * \endcode + * + * To be able to show a progress of the operation, the following steps + * are recommended: + * - Use a DirectorySizeJob to count the number of directories. + * - Use a timer to show the current count of directories by invoking + * DirectorySizeJob::totalSubdirs() until the result signal is emitted. + * - Use the ApplyViewPropsJob. + * - Use a timer to show the progress by invoking ApplyViwePropsJob::progress(). + * In combination with the total directory count it is possible to show a + * progress bar now. + */ +class ApplyViewPropsJob : public KIO::Job +{ + Q_OBJECT + +public: + /** + * @param dir Directory where the view properties should be applied to + * (including sub directories). + * @param viewProps View properties for the directory \a dir including its + * sub directories. + */ + ApplyViewPropsJob(const KUrl& dir, const ViewProperties& viewProps); + virtual ~ApplyViewPropsJob(); + int progress() const; + +private slots: + virtual void slotResult(KJob* job); + void slotEntries(KIO::Job*, const KIO::UDSEntryList&); + +private: + ViewProperties* m_viewProps; + int m_currentItem; + int m_progress; + KUrl m_dir; +}; + +inline int ApplyViewPropsJob::progress() const +{ + return m_progress; +} + +#endif diff --git a/src/settings/columnviewsettingspage.cpp b/src/settings/columnviewsettingspage.cpp new file mode 100644 index 000000000..5918eaf92 --- /dev/null +++ b/src/settings/columnviewsettingspage.cpp @@ -0,0 +1,155 @@ +/*************************************************************************** + * Copyright (C) 2006 by Peter Penz * + * * + * 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 of the License, 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. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#include "columnviewsettingspage.h" + +#include "dolphinfontrequester.h" +#include "dolphinsettings.h" +#include "dolphin_columnmodesettings.h" +#include "iconsizegroupbox.h" +#include "zoomlevelinfo.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +ColumnViewSettingsPage::ColumnViewSettingsPage(QWidget* parent) : + ViewSettingsPageBase(parent), + m_iconSizeGroupBox(0), + m_fontRequester(0), + m_textWidthBox(0) +{ + const int spacing = KDialog::spacingHint(); + const int margin = KDialog::marginHint(); + const QSizePolicy sizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); + + setSpacing(spacing); + setMargin(margin); + + // Create "Icon" properties + m_iconSizeGroupBox = new IconSizeGroupBox(this); + m_iconSizeGroupBox->setSizePolicy(sizePolicy); + + const int min = ZoomLevelInfo::minimumLevel(); + const int max = ZoomLevelInfo::maximumLevel(); + m_iconSizeGroupBox->setDefaultSizeRange(min, max); + m_iconSizeGroupBox->setPreviewSizeRange(min, max); + + connect(m_iconSizeGroupBox, SIGNAL(defaultSizeChanged(int)), + this, SIGNAL(changed())); + connect(m_iconSizeGroupBox, SIGNAL(previewSizeChanged(int)), + this, SIGNAL(changed())); + + // create "Text" properties + QGroupBox* textGroup = new QGroupBox(i18nc("@title:group", "Text"), this); + textGroup->setSizePolicy(sizePolicy); + + QLabel* fontLabel = new QLabel(i18nc("@label:listbox", "Font:"), textGroup); + m_fontRequester = new DolphinFontRequester(textGroup); + connect(m_fontRequester, SIGNAL(changed()), this, SIGNAL(changed())); + + QLabel* textWidthLabel = new QLabel(i18nc("@label:listbox", "Text width:"), textGroup); + m_textWidthBox = new KComboBox(textGroup); + m_textWidthBox->addItem(i18nc("@item:inlistbox Text width", "Small")); + m_textWidthBox->addItem(i18nc("@item:inlistbox Text width", "Medium")); + m_textWidthBox->addItem(i18nc("@item:inlistbox Text width", "Large")); + connect(m_textWidthBox, SIGNAL(activated(int)), this, SIGNAL(changed())); + + QGridLayout* textGroupLayout = new QGridLayout(textGroup); + textGroupLayout->addWidget(fontLabel, 0, 0, Qt::AlignRight); + textGroupLayout->addWidget(m_fontRequester, 0, 1); + textGroupLayout->addWidget(textWidthLabel, 1, 0, Qt::AlignRight); + textGroupLayout->addWidget(m_textWidthBox, 1, 1); + + // Add a dummy widget with no restriction regarding + // a vertical resizing. This assures that the dialog layout + // is not stretched vertically. + new QWidget(this); + + loadSettings(); +} + +ColumnViewSettingsPage::~ColumnViewSettingsPage() +{ +} + +void ColumnViewSettingsPage::applySettings() +{ + ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings(); + + const int iconSize = ZoomLevelInfo::iconSizeForZoomLevel(m_iconSizeGroupBox->defaultSizeValue()); + const int previewSize = ZoomLevelInfo::iconSizeForZoomLevel(m_iconSizeGroupBox->previewSizeValue()); + settings->setIconSize(iconSize); + settings->setPreviewSize(previewSize); + + const QFont font = m_fontRequester->font(); + settings->setUseSystemFont(m_fontRequester->mode() == DolphinFontRequester::SystemFont); + settings->setFontFamily(font.family()); + settings->setFontSize(font.pointSize()); + settings->setItalicFont(font.italic()); + settings->setFontWeight(font.weight()); + + // TODO: + //const int columnWidth = 150 + (m_columnWidthSlider->value() * 50); + //settings->setColumnWidth(columnWidth); +} + +void ColumnViewSettingsPage::restoreDefaults() +{ + ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings(); + settings->setDefaults(); + loadSettings(); +} + +void ColumnViewSettingsPage::loadSettings() +{ + ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings(); + + const QSize iconSize(settings->iconSize(), settings->iconSize()); + const int iconSizeValue = ZoomLevelInfo::zoomLevelForIconSize(iconSize); + m_iconSizeGroupBox->setDefaultSizeValue(iconSizeValue); + + const QSize previewSize(settings->previewSize(), settings->previewSize()); + const int previewSizeValue = ZoomLevelInfo::zoomLevelForIconSize(previewSize); + m_iconSizeGroupBox->setPreviewSizeValue(previewSizeValue); + + if (settings->useSystemFont()) { + m_fontRequester->setMode(DolphinFontRequester::SystemFont); + } else { + QFont font(settings->fontFamily(), + settings->fontSize()); + font.setItalic(settings->italicFont()); + font.setWeight(settings->fontWeight()); + m_fontRequester->setMode(DolphinFontRequester::CustomFont); + m_fontRequester->setCustomFont(font); + } + + // TODO: + //m_columnWidthSlider->setValue((settings->columnWidth() - 150) / 50); +} + +#include "columnviewsettingspage.moc" diff --git a/src/settings/columnviewsettingspage.h b/src/settings/columnviewsettingspage.h new file mode 100644 index 000000000..c723ed635 --- /dev/null +++ b/src/settings/columnviewsettingspage.h @@ -0,0 +1,61 @@ +/*************************************************************************** + * Copyright (C) 2006 by Peter Penz * + * * + * 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 of the License, 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. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#ifndef COLUMNVIEWSETTINGSPAGE_H +#define COLUMNVIEWSETTINGSPAGE_H + +#include + +class DolphinMainWindow; +class DolphinFontRequester; +class IconSizeGroupBox; +class KComboBox; + +/** + * @brief Represents the page from the Dolphin Settings which allows + * to modify the settings for the details view. + */ +class ColumnViewSettingsPage : public ViewSettingsPageBase +{ + Q_OBJECT + +public: + ColumnViewSettingsPage(QWidget* parent); + virtual ~ColumnViewSettingsPage(); + + /** + * Applies the settings for the details view. + * The settings are persisted automatically when + * closing Dolphin. + */ + virtual void applySettings(); + + /** Restores the settings to default values. */ + virtual void restoreDefaults(); + +private: + void loadSettings(); + +private: + IconSizeGroupBox* m_iconSizeGroupBox; + DolphinFontRequester* m_fontRequester; + KComboBox* m_textWidthBox; +}; + +#endif diff --git a/src/settings/detailsviewsettingspage.cpp b/src/settings/detailsviewsettingspage.cpp new file mode 100644 index 000000000..0c47caf24 --- /dev/null +++ b/src/settings/detailsviewsettingspage.cpp @@ -0,0 +1,147 @@ +/*************************************************************************** + * Copyright (C) 2006 by Peter Penz * + * * + * 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 of the License, 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. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#include "detailsviewsettingspage.h" + +#include "iconsizegroupbox.h" +#include "dolphinfontrequester.h" +#include "dolphinsettings.h" +#include "dolphin_detailsmodesettings.h" +#include "zoomlevelinfo.h" + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +DetailsViewSettingsPage::DetailsViewSettingsPage(QWidget* parent) : + ViewSettingsPageBase(parent), + m_iconSizeGroupBox(0), + m_fontRequester(0), + m_expandableFolders(0) +{ + const int spacing = KDialog::spacingHint(); + const int margin = KDialog::marginHint(); + const QSizePolicy sizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); + + setSpacing(spacing); + setMargin(margin); + + // Create "Icon" properties + m_iconSizeGroupBox = new IconSizeGroupBox(this); + m_iconSizeGroupBox->setSizePolicy(sizePolicy); + + const int min = ZoomLevelInfo::minimumLevel(); + const int max = ZoomLevelInfo::maximumLevel(); + m_iconSizeGroupBox->setDefaultSizeRange(min, max); + m_iconSizeGroupBox->setPreviewSizeRange(min, max); + + connect(m_iconSizeGroupBox, SIGNAL(defaultSizeChanged(int)), + this, SIGNAL(changed())); + connect(m_iconSizeGroupBox, SIGNAL(previewSizeChanged(int)), + this, SIGNAL(changed())); + + // create "Text" properties + QWidget* textGroup = new QGroupBox(i18nc("@title:group", "Text"), this); + textGroup->setSizePolicy(sizePolicy); + + QLabel* fontLabel = new QLabel(i18nc("@label:listbox", "Font:"), textGroup); + m_fontRequester = new DolphinFontRequester(textGroup); + connect(m_fontRequester, SIGNAL(changed()), this, SIGNAL(changed())); + + QHBoxLayout* textLayout = new QHBoxLayout(textGroup); + textLayout->addWidget(fontLabel, 0, Qt::AlignRight); + textLayout->addWidget(m_fontRequester); + + // create "Expandable Folders" checkbox + m_expandableFolders = new QCheckBox(i18nc("@option:check", "Expandable folders"), this); + connect(m_expandableFolders, SIGNAL(toggled(bool)), this, SIGNAL(changed())); + + // Add a dummy widget with no restriction regarding + // a vertical resizing. This assures that the dialog layout + // is not stretched vertically. + new QWidget(this); + + loadSettings(); +} + +DetailsViewSettingsPage::~DetailsViewSettingsPage() +{ +} + +void DetailsViewSettingsPage::applySettings() +{ + DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings(); + + const int iconSize = ZoomLevelInfo::iconSizeForZoomLevel(m_iconSizeGroupBox->defaultSizeValue()); + const int previewSize = ZoomLevelInfo::iconSizeForZoomLevel(m_iconSizeGroupBox->previewSizeValue()); + settings->setIconSize(iconSize); + settings->setPreviewSize(previewSize); + + const QFont font = m_fontRequester->font(); + settings->setUseSystemFont(m_fontRequester->mode() == DolphinFontRequester::SystemFont); + settings->setFontFamily(font.family()); + settings->setFontSize(font.pointSize()); + settings->setItalicFont(font.italic()); + settings->setFontWeight(font.weight()); + + settings->setExpandableFolders(m_expandableFolders->isChecked()); +} + +void DetailsViewSettingsPage::restoreDefaults() +{ + DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings(); + settings->setDefaults(); + loadSettings(); +} + +void DetailsViewSettingsPage::loadSettings() +{ + DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings(); + + const QSize iconSize(settings->iconSize(), settings->iconSize()); + const int iconSizeValue = ZoomLevelInfo::zoomLevelForIconSize(iconSize); + m_iconSizeGroupBox->setDefaultSizeValue(iconSizeValue); + + const QSize previewSize(settings->previewSize(), settings->previewSize()); + const int previewSizeValue = ZoomLevelInfo::zoomLevelForIconSize(previewSize); + m_iconSizeGroupBox->setPreviewSizeValue(previewSizeValue); + + if (settings->useSystemFont()) { + m_fontRequester->setMode(DolphinFontRequester::SystemFont); + } else { + QFont font(settings->fontFamily(), + settings->fontSize()); + font.setItalic(settings->italicFont()); + font.setWeight(settings->fontWeight()); + m_fontRequester->setMode(DolphinFontRequester::CustomFont); + m_fontRequester->setCustomFont(font); + } + + m_expandableFolders->setChecked(settings->expandableFolders()); +} + +#include "detailsviewsettingspage.moc" diff --git a/src/settings/detailsviewsettingspage.h b/src/settings/detailsviewsettingspage.h new file mode 100644 index 000000000..58e3fd905 --- /dev/null +++ b/src/settings/detailsviewsettingspage.h @@ -0,0 +1,60 @@ +/*************************************************************************** + * Copyright (C) 2006 by Peter Penz * + * * + * 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 of the License, 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. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#ifndef DETAILSVIEWSETTINGSPAGE_H +#define DETAILSVIEWSETTINGSPAGE_H + +#include + +class DolphinFontRequester; +class IconSizeGroupBox; +class QCheckBox; + +/** + * @brief Represents the page from the Dolphin Settings which allows + * to modify the settings for the details view. + */ +class DetailsViewSettingsPage : public ViewSettingsPageBase +{ + Q_OBJECT + +public: + DetailsViewSettingsPage(QWidget* parent); + virtual ~DetailsViewSettingsPage(); + + /** + * Applies the settings for the details view. + * The settings are persisted automatically when + * closing Dolphin. + */ + virtual void applySettings(); + + /** Restores the settings to default values. */ + virtual void restoreDefaults(); + +private: + void loadSettings(); + +private: + IconSizeGroupBox* m_iconSizeGroupBox; + DolphinFontRequester* m_fontRequester; + QCheckBox* m_expandableFolders; +}; + +#endif diff --git a/src/settings/dolphin_columnmodesettings.kcfg b/src/settings/dolphin_columnmodesettings.kcfg new file mode 100644 index 000000000..4fd5ecc6e --- /dev/null +++ b/src/settings/dolphin_columnmodesettings.kcfg @@ -0,0 +1,41 @@ + + + + + kiconloader.h + kglobalsettings.h + + + + KGlobalSettings::generalFont().family() + + + + true + + + + KGlobalSettings::generalFont().pointSize() + + + + false + + + + 0 + + + + KIconLoader::SizeSmall + + + + KIconLoader::SizeLarge + + + + 250 + + + diff --git a/src/settings/dolphin_columnmodesettings.kcfgc b/src/settings/dolphin_columnmodesettings.kcfgc new file mode 100644 index 000000000..55134335a --- /dev/null +++ b/src/settings/dolphin_columnmodesettings.kcfgc @@ -0,0 +1,4 @@ +File=dolphin_columnmodesettings.kcfg +ClassName=ColumnModeSettings +Singleton=false +Mutators=true diff --git a/src/settings/dolphin_detailsmodesettings.kcfg b/src/settings/dolphin_detailsmodesettings.kcfg new file mode 100644 index 000000000..780d70540 --- /dev/null +++ b/src/settings/dolphin_detailsmodesettings.kcfg @@ -0,0 +1,41 @@ + + + + + kiconloader.h + kglobalsettings.h + + + + KGlobalSettings::generalFont().family() + + + + true + + + + KGlobalSettings::generalFont().pointSize() + + + + false + + + + 0 + + + + KIconLoader::SizeSmall + + + + KIconLoader::SizeLarge + + + + false + + + diff --git a/src/settings/dolphin_detailsmodesettings.kcfgc b/src/settings/dolphin_detailsmodesettings.kcfgc new file mode 100644 index 000000000..06da2e9e0 --- /dev/null +++ b/src/settings/dolphin_detailsmodesettings.kcfgc @@ -0,0 +1,4 @@ +File=dolphin_detailsmodesettings.kcfg +ClassName=DetailsModeSettings +Singleton=false +Mutators=true diff --git a/src/settings/dolphin_directoryviewpropertysettings.kcfg b/src/settings/dolphin_directoryviewpropertysettings.kcfg new file mode 100644 index 000000000..ead1325de --- /dev/null +++ b/src/settings/dolphin_directoryviewpropertysettings.kcfg @@ -0,0 +1,65 @@ + + + kfileitemdelegate.h + + + + + + When this option is enabled hidden files, such as those starting with a '.', will be shown in the file view. + false + + + + + + + This option controls the style of the view. Currently supported values include icons (0), details (1) and column (2) views. + DolphinView::IconsView + 0 + DolphinView::MaxModeEnum + + + + + When this option is enabled, a preview of the file content is shown as an icon. + false + + + + + When this option is enabled, the sorted items are summarized by their category. + false + + + + + This option defines which attribute (name, size, date, etc.) sorting is performed on. + DolphinView::SortByName + 0 + DolphinView::MaxSortEnum + + + + + Qt::AscendingOrder + Qt::AscendingOrder + Qt::DescendingOrder + + + + + 0 + + + + + The last time these properties were changed by the user. + + + + + diff --git a/src/settings/dolphin_directoryviewpropertysettings.kcfgc b/src/settings/dolphin_directoryviewpropertysettings.kcfgc new file mode 100644 index 000000000..753642f8c --- /dev/null +++ b/src/settings/dolphin_directoryviewpropertysettings.kcfgc @@ -0,0 +1,6 @@ +File=dolphin_directoryviewpropertysettings.kcfg +Singleton=false +ClassName=ViewPropertySettings +Mutators=true +GlobalEnums=true +IncludeFiles=dolphinview.h,qnamespace.h diff --git a/src/settings/dolphin_generalsettings.kcfg b/src/settings/dolphin_generalsettings.kcfg new file mode 100644 index 000000000..2f4defa92 --- /dev/null +++ b/src/settings/dolphin_generalsettings.kcfg @@ -0,0 +1,71 @@ + + + + + QDir + + + + false + + + + false + + + + true + + + + QDir::homePath() + + + + false + + + + false + + + + false + + + + false + + + + false + + + + true + + + + false + + + + false + + + + + + + false + + + + true + + + + false + + + diff --git a/src/settings/dolphin_generalsettings.kcfgc b/src/settings/dolphin_generalsettings.kcfgc new file mode 100644 index 000000000..91b1fee46 --- /dev/null +++ b/src/settings/dolphin_generalsettings.kcfgc @@ -0,0 +1,4 @@ +File=dolphin_generalsettings.kcfg +ClassName=GeneralSettings +Singleton=false +Mutators=true diff --git a/src/settings/dolphin_iconsmodesettings.kcfg b/src/settings/dolphin_iconsmodesettings.kcfg new file mode 100644 index 000000000..1311f6d20 --- /dev/null +++ b/src/settings/dolphin_iconsmodesettings.kcfg @@ -0,0 +1,67 @@ + + + + + kglobalsettings.h + kiconloader.h + QListView + + + + QListView::TopToBottom + + + + true + + + + KGlobalSettings::generalFont().family() + + + + KGlobalSettings::generalFont().pointSize() + + + + false + + + + 0 + + + + + KIconLoader::SizeMedium + QFontMetrics(KGlobalSettings::generalFont()).height() * 2 + 10 + + + + + 96 + + + + 8 + + + + KIconLoader::SizeMedium + + + + + 2 + + + + KIconLoader::SizeHuge + + + diff --git a/src/settings/dolphin_iconsmodesettings.kcfgc b/src/settings/dolphin_iconsmodesettings.kcfgc new file mode 100644 index 000000000..9987ce938 --- /dev/null +++ b/src/settings/dolphin_iconsmodesettings.kcfgc @@ -0,0 +1,4 @@ +File=dolphin_iconsmodesettings.kcfg +ClassName=IconsModeSettings +Singleton=false +Mutators=true diff --git a/src/settings/dolphinfontrequester.cpp b/src/settings/dolphinfontrequester.cpp new file mode 100644 index 000000000..2fc444029 --- /dev/null +++ b/src/settings/dolphinfontrequester.cpp @@ -0,0 +1,111 @@ +/*************************************************************************** + * Copyright (C) 2008 by Peter Penz * + * * + * 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 of the License, 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. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#include "dolphinfontrequester.h" + +#include +#include +#include +#include + +#include +#include + +DolphinFontRequester::DolphinFontRequester(QWidget* parent) : + KHBox(parent), + m_modeCombo(0), + m_chooseFontButton(0), + m_mode(SystemFont), + m_customFont() +{ + setSpacing(KDialog::spacingHint()); + + m_modeCombo = new KComboBox(this); + m_modeCombo->addItem(i18nc("@item:inlistbox Font", "System Font")); + m_modeCombo->addItem(i18nc("@item:inlistbox Font", "Custom Font")); + connect(m_modeCombo, SIGNAL(activated(int)), + this, SLOT(changeMode(int))); + + m_chooseFontButton = new QPushButton(i18nc("@action:button Choose font", "Choose..."), this); + connect(m_chooseFontButton, SIGNAL(clicked()), + this, SLOT(openFontDialog())); + + changeMode(m_modeCombo->currentIndex()); +} + +DolphinFontRequester::~DolphinFontRequester() +{ +} + +void DolphinFontRequester::setMode(Mode mode) +{ + m_mode = mode; + m_modeCombo->setCurrentIndex(m_mode); + m_modeCombo->setFont(font()); + m_chooseFontButton->setEnabled(m_mode == CustomFont); +} + +DolphinFontRequester::Mode DolphinFontRequester::mode() const +{ + return m_mode; +} + +QFont DolphinFontRequester::font() const +{ + return (m_mode == CustomFont) ? m_customFont : KGlobalSettings::generalFont(); +} + +void DolphinFontRequester::setCustomFont(const QFont& font) +{ + m_customFont = font; +} + +QFont DolphinFontRequester::customFont() const +{ + return m_customFont; +} + +bool DolphinFontRequester::event(QEvent* event) +{ + if (event->type() == QEvent::Polish) { + m_modeCombo->setFont(font()); + } + return KHBox::event(event); +} + +void DolphinFontRequester::openFontDialog() +{ + QFont font; + const int result = KFontDialog::getFont(font, + KFontChooser::NoDisplayFlags, + this); + if (result == KFontDialog::Accepted) { + m_customFont = font; + m_modeCombo->setFont(m_customFont); + emit changed(); + } +} + +void DolphinFontRequester::changeMode(int index) +{ + setMode((index == CustomFont) ? CustomFont : SystemFont); + emit changed(); +} + +#include "dolphinfontrequester.moc" diff --git a/src/settings/dolphinfontrequester.h b/src/settings/dolphinfontrequester.h new file mode 100644 index 000000000..03a062b2e --- /dev/null +++ b/src/settings/dolphinfontrequester.h @@ -0,0 +1,79 @@ +/*************************************************************************** + * Copyright (C) 2008 by Peter Penz * + * * + * 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 of the License, 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. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#ifndef DOLPHINFONTREQUESTER_H +#define DOLPHINFONTREQUESTER_H + +#include + +#include + +class KComboBox; +class QPushButton; + +/** + * @brief Allows to select between using the system font or a custom font. + */ +class DolphinFontRequester : public KHBox +{ + Q_OBJECT + +public: + enum Mode + { + SystemFont = 0, + CustomFont = 1 + }; + + DolphinFontRequester(QWidget* parent); + virtual ~DolphinFontRequester(); + + void setMode(Mode mode); + Mode mode() const; + + /** + * Returns the custom font (see DolphinFontRequester::customFont()), + * if the mode is \a CustomFont, otherwise the system font is + * returned. + */ + QFont font() const; + + void setCustomFont(const QFont& font); + QFont customFont() const; + +signals: + /** Is emitted, if the font has been changed. */ + void changed(); + +protected: + bool event(QEvent* event); + +private slots: + void openFontDialog(); + void changeMode(int index); + +private: + KComboBox* m_modeCombo; + QPushButton* m_chooseFontButton; + + Mode m_mode; + QFont m_customFont; +}; + +#endif diff --git a/src/settings/dolphinsettings.cpp b/src/settings/dolphinsettings.cpp new file mode 100644 index 000000000..5b91001ef --- /dev/null +++ b/src/settings/dolphinsettings.cpp @@ -0,0 +1,78 @@ +/*************************************************************************** + * Copyright (C) 2006 by Peter Penz (peter.penz@gmx.at), * + * Cvetoslav Ludmiloff and Patrice Tremblay * + * * + * 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 of the License, 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. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#include "dolphinsettings.h" + +#include +#include +#include +#include + +#include "dolphin_columnmodesettings.h" +#include "dolphin_detailsmodesettings.h" +#include "dolphin_generalsettings.h" +#include "dolphin_iconsmodesettings.h" + +class DolphinSettingsSingleton +{ +public: + DolphinSettings instance; +}; +K_GLOBAL_STATIC(DolphinSettingsSingleton, s_settings) + +DolphinSettings& DolphinSettings::instance() +{ + return s_settings->instance; +} + +void DolphinSettings::save() +{ + m_generalSettings->writeConfig(); + m_iconsModeSettings->writeConfig(); + m_detailsModeSettings->writeConfig(); + m_columnModeSettings->writeConfig(); +} + +DolphinSettings::DolphinSettings() +{ + m_generalSettings = new GeneralSettings(); + m_iconsModeSettings = new IconsModeSettings(); + m_detailsModeSettings = new DetailsModeSettings(); + m_columnModeSettings = new ColumnModeSettings(); + m_placesModel = new KFilePlacesModel(); +} + +DolphinSettings::~DolphinSettings() +{ + delete m_generalSettings; + m_generalSettings = 0; + + delete m_iconsModeSettings; + m_iconsModeSettings = 0; + + delete m_detailsModeSettings; + m_detailsModeSettings = 0; + + delete m_columnModeSettings; + m_columnModeSettings = 0; + + delete m_placesModel; + m_placesModel = 0; +} diff --git a/src/settings/dolphinsettings.h b/src/settings/dolphinsettings.h new file mode 100644 index 000000000..55fa327ef --- /dev/null +++ b/src/settings/dolphinsettings.h @@ -0,0 +1,92 @@ +/*************************************************************************** + * Copyright (C) 2006 by Peter Penz * + * peter.penz@gmx.at * + * * + * 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 of the License, 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. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#ifndef DOLPHINSETTINGS_H +#define DOLPHINSETTINGS_H + +#include + +class ColumnModeSettings; +class DetailsModeSettings; +class GeneralSettings; +class IconsModeSettings; +class KFilePlacesModel; + +/** + * @brief Manages and stores all settings from Dolphin. + * + * The following properties are stored: + * - home URL + * - default view mode + * - URL navigator state (editable or not) + * - split view + * - properties for views + */ +class LIBDOLPHINPRIVATE_EXPORT DolphinSettings +{ +public: + static DolphinSettings& instance(); + + GeneralSettings* generalSettings() const; + IconsModeSettings* iconsModeSettings() const; + DetailsModeSettings* detailsModeSettings() const; + ColumnModeSettings* columnModeSettings() const; + KFilePlacesModel* placesModel() const; + virtual void save(); + +protected: + DolphinSettings(); + virtual ~DolphinSettings(); + friend class DolphinSettingsSingleton; + +private: + GeneralSettings* m_generalSettings; + IconsModeSettings* m_iconsModeSettings; + DetailsModeSettings* m_detailsModeSettings; + ColumnModeSettings* m_columnModeSettings; + KFilePlacesModel* m_placesModel; +}; + +inline GeneralSettings* DolphinSettings::generalSettings() const +{ + return m_generalSettings; +} + +inline IconsModeSettings* DolphinSettings::iconsModeSettings() const +{ + return m_iconsModeSettings; +} + +inline DetailsModeSettings* DolphinSettings::detailsModeSettings() const +{ + return m_detailsModeSettings; +} + +inline ColumnModeSettings* DolphinSettings::columnModeSettings() const +{ + return m_columnModeSettings; +} + +inline KFilePlacesModel* DolphinSettings::placesModel() const +{ + return m_placesModel; +} + +#endif diff --git a/src/settings/dolphinsettingsdialog.cpp b/src/settings/dolphinsettingsdialog.cpp new file mode 100644 index 000000000..54ac74bde --- /dev/null +++ b/src/settings/dolphinsettingsdialog.cpp @@ -0,0 +1,114 @@ +/*************************************************************************** + * Copyright (C) 2006 by Peter Penz * + * peter.penz@gmx.at * + * * + * 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 of the License, 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. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#include "dolphinsettingsdialog.h" + +#include +#include +#include "generalsettingspage.h" +#include "startupsettingspage.h" +#include "viewsettingspage.h" + +#include +#include +#include + +DolphinSettingsDialog::DolphinSettingsDialog(DolphinMainWindow* mainWindow) : + KPageDialog(mainWindow), + m_pages() + +{ + const QSize minSize = minimumSize(); + setMinimumSize(QSize(512, minSize.height())); + + setFaceType(List); + setCaption(i18nc("@title:window", "Dolphin Preferences")); + setButtons(Ok | Apply | Cancel | Default); + enableButtonApply(false); + setDefaultButton(Ok); + + StartupSettingsPage* startupSettingsPage = new StartupSettingsPage(mainWindow, this); + KPageWidgetItem* startupSettingsFrame = addPage(startupSettingsPage, + i18nc("@title:group", "Startup")); + startupSettingsFrame->setIcon(KIcon("go-home")); + connect(startupSettingsPage, SIGNAL(changed()), this, SLOT(enableApply())); + + ViewSettingsPage* viewSettingsPage = new ViewSettingsPage(mainWindow, this); + KPageWidgetItem* viewSettingsFrame = addPage(viewSettingsPage, + i18nc("@title:group", "View Modes")); + viewSettingsFrame->setIcon(KIcon("view-choose")); + connect(viewSettingsPage, SIGNAL(changed()), this, SLOT(enableApply())); + + GeneralSettingsPage* generalSettingsPage = new GeneralSettingsPage(mainWindow, this); + KPageWidgetItem* generalSettingsFrame = addPage(generalSettingsPage, + i18nc("@title:group General settings", "General")); + generalSettingsFrame->setIcon(KIcon("system-run")); + connect(generalSettingsPage, SIGNAL(changed()), this, SLOT(enableApply())); + + const KConfigGroup dialogConfig(KSharedConfig::openConfig("dolphinrc"), "SettingsDialog"); + restoreDialogSize(dialogConfig); + + m_pages.append(startupSettingsPage); + m_pages.append(viewSettingsPage); + m_pages.append(generalSettingsPage); +} + +DolphinSettingsDialog::~DolphinSettingsDialog() +{ + KConfigGroup dialogConfig(KSharedConfig::openConfig("dolphinrc"), "SettingsDialog"); + saveDialogSize(dialogConfig); +} + +void DolphinSettingsDialog::slotButtonClicked(int button) +{ + if ((button == Ok) || (button == Apply)) { + applySettings(); + } else if (button == Default) { + const QString text(i18nc("@info", "All settings will be reset to default values. Do you want to continue?")); + if (KMessageBox::questionYesNo(this, text) == KMessageBox::Yes) { + restoreDefaults(); + } + } + + KPageDialog::slotButtonClicked(button); +} + +void DolphinSettingsDialog::enableApply() +{ + enableButtonApply(true); +} + +void DolphinSettingsDialog::applySettings() +{ + foreach (SettingsPageBase* page, m_pages) { + page->applySettings(); + } + DolphinApplication::app()->refreshMainWindows(); +} + +void DolphinSettingsDialog::restoreDefaults() +{ + foreach (SettingsPageBase* page, m_pages) { + page->restoreDefaults(); + } + DolphinApplication::app()->refreshMainWindows(); +} + +#include "dolphinsettingsdialog.moc" diff --git a/src/settings/dolphinsettingsdialog.h b/src/settings/dolphinsettingsdialog.h new file mode 100644 index 000000000..fc17b3774 --- /dev/null +++ b/src/settings/dolphinsettingsdialog.h @@ -0,0 +1,60 @@ +/*************************************************************************** + * Copyright (C) 2006 by Peter Penz * + * peter.penz@gmx.at * + * * + * 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 of the License, 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. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#ifndef DOLPHINSETTINGSDIALOG_H +#define DOLPHINSETTINGSDIALOG_H + +#include + +class DolphinMainWindow; +class SettingsPageBase; + +/** + * @brief Settings dialog for Dolphin. + * + * Contains the pages for startup settings, general settings and view settings. + * + * @author Peter Penz + */ +class DolphinSettingsDialog : public KPageDialog +{ + Q_OBJECT + +public: + explicit DolphinSettingsDialog(DolphinMainWindow* mainWindow); + virtual ~DolphinSettingsDialog(); + +protected slots: + /** @see KDialog::slotButtonClicked() */ + virtual void slotButtonClicked(int button); + +private slots: + /** Enables the Apply button. */ + void enableApply(); + +private: + void applySettings(); + void restoreDefaults(); + +private: + QList m_pages; +}; + +#endif diff --git a/src/settings/generalsettingspage.cpp b/src/settings/generalsettingspage.cpp new file mode 100644 index 000000000..86b6f1939 --- /dev/null +++ b/src/settings/generalsettingspage.cpp @@ -0,0 +1,170 @@ +/*************************************************************************** + * Copyright (C) 2006 by Peter Penz (peter.penz@gmx.at) and * + * and Patrice Tremblay * + * * + * 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 of the License, 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. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#include "generalsettingspage.h" + +#include "settings/dolphinsettings.h" + +#include "dolphin_generalsettings.h" + +#include +#include +#include + +#include +#include +#include +#include + +GeneralSettingsPage::GeneralSettingsPage(DolphinMainWindow* mainWin, QWidget* parent) : + SettingsPageBase(parent), + m_confirmMoveToTrash(0), + m_confirmDelete(0), + m_showDeleteCommand(0), + m_showCopyMoveMenu(0), + m_showZoomSlider(0), + m_showSpaceInfo(0), + m_browseThroughArchives(0), + m_renameInline(0), + m_autoExpandFolders(0) +{ + Q_UNUSED(mainWin); + + const int spacing = KDialog::spacingHint(); + + QVBoxLayout* topLayout = new QVBoxLayout(this); + KVBox* vBox = new KVBox(this); + vBox->setSpacing(spacing); + + // create 'Ask Confirmation For' group + QGroupBox* confirmBox = new QGroupBox(i18nc("@title:group", "Ask For Confirmation When"), vBox); + m_confirmMoveToTrash = new QCheckBox(i18nc("@option:check Ask for Confirmation When", + "Moving files or folders to trash"), confirmBox); + connect(m_confirmMoveToTrash, SIGNAL(toggled(bool)), this, SIGNAL(changed())); + m_confirmDelete = new QCheckBox(i18nc("@option:check Ask for Confirmation When", + "Deleting files or folders"), confirmBox); + connect(m_confirmDelete, SIGNAL(toggled(bool)), this, SIGNAL(changed())); + + QVBoxLayout* confirmBoxLayout = new QVBoxLayout(confirmBox); + confirmBoxLayout->addWidget(m_confirmMoveToTrash); + confirmBoxLayout->addWidget(m_confirmDelete); + + QGroupBox* contextMenuBox = new QGroupBox(i18nc("@title:group", "Context Menu"), vBox); + + // create 'Show the command 'Delete' in context menu' checkbox + m_showDeleteCommand = new QCheckBox(i18nc("@option:check", "Show 'Delete' command"), contextMenuBox); + connect(m_showDeleteCommand, SIGNAL(toggled(bool)), this, SIGNAL(changed())); + + m_showCopyMoveMenu = new QCheckBox(i18nc("@option:check", "Show 'Copy To' and 'Move To' commands"), contextMenuBox); + connect(m_showCopyMoveMenu, SIGNAL(toggled(bool)), this, SIGNAL(changed())); + + QVBoxLayout* contextMenuBoxLayout = new QVBoxLayout(contextMenuBox); + contextMenuBoxLayout->addWidget(m_showDeleteCommand); + contextMenuBoxLayout->addWidget(m_showCopyMoveMenu); + + QGroupBox* statusBarBox = new QGroupBox(i18nc("@title:group", "Status Bar"), vBox); + + m_showZoomSlider = new QCheckBox(i18nc("@option:check", "Show zoom slider"), statusBarBox); + connect(m_showZoomSlider, SIGNAL(toggled(bool)), this, SIGNAL(changed())); + + m_showSpaceInfo = new QCheckBox(i18nc("@option:check", "Show space information"), statusBarBox); + connect(m_showSpaceInfo, SIGNAL(toggled(bool)), this, SIGNAL(changed())); + + QVBoxLayout* statusBarBoxLayout = new QVBoxLayout(statusBarBox); + statusBarBoxLayout->addWidget(m_showZoomSlider); + statusBarBoxLayout->addWidget(m_showSpaceInfo); + + m_browseThroughArchives = new QCheckBox(i18nc("@option:check", "Browse through archives"), vBox); + connect(m_browseThroughArchives, SIGNAL(toggled(bool)), this, SIGNAL(changed())); + + m_renameInline = new QCheckBox(i18nc("@option:check", "Rename inline"), vBox); + connect(m_renameInline, SIGNAL(toggled(bool)), this, SIGNAL(changed())); + + m_autoExpandFolders = new QCheckBox(i18nc("option:check", "Open folders during drag operations"), vBox); + connect(m_autoExpandFolders, SIGNAL(toggled(bool)), this, SIGNAL(changed())); + + // Add a dummy widget with no restriction regarding + // a vertical resizing. This assures that the dialog layout + // is not stretched vertically. + new QWidget(vBox); + + topLayout->addWidget(vBox); + + loadSettings(); +} + +GeneralSettingsPage::~GeneralSettingsPage() +{ +} + +void GeneralSettingsPage::applySettings() +{ + GeneralSettings* settings = DolphinSettings::instance().generalSettings(); + + KSharedConfig::Ptr kioConfig = KSharedConfig::openConfig("kiorc", KConfig::NoGlobals); + KConfigGroup confirmationGroup(kioConfig, "Confirmations"); + confirmationGroup.writeEntry("ConfirmTrash", m_confirmMoveToTrash->isChecked()); + confirmationGroup.writeEntry("ConfirmDelete", m_confirmDelete->isChecked()); + confirmationGroup.sync(); + + KSharedConfig::Ptr globalConfig = KSharedConfig::openConfig("kdeglobals", KConfig::NoGlobals); + KConfigGroup configGroup(globalConfig, "KDE"); + configGroup.writeEntry("ShowDeleteCommand", m_showDeleteCommand->isChecked()); + configGroup.sync(); + + settings->setShowCopyMoveMenu(m_showCopyMoveMenu->isChecked()); + settings->setShowZoomSlider(m_showZoomSlider->isChecked()); + settings->setShowSpaceInfo(m_showSpaceInfo->isChecked()); + settings->setBrowseThroughArchives(m_browseThroughArchives->isChecked()); + settings->setRenameInline(m_renameInline->isChecked()); + settings->setAutoExpandFolders(m_autoExpandFolders->isChecked()); +} + +void GeneralSettingsPage::restoreDefaults() +{ + GeneralSettings* settings = DolphinSettings::instance().generalSettings(); + settings->setDefaults(); + + // TODO: reset default settings for trash and show delete command... + + loadSettings(); +} + +void GeneralSettingsPage::loadSettings() +{ + KSharedConfig::Ptr kioConfig = KSharedConfig::openConfig("kiorc", KConfig::IncludeGlobals); + const KConfigGroup confirmationGroup(kioConfig, "Confirmations"); + m_confirmMoveToTrash->setChecked(confirmationGroup.readEntry("ConfirmTrash", false)); + m_confirmDelete->setChecked(confirmationGroup.readEntry("ConfirmDelete", true)); + + KSharedConfig::Ptr globalConfig = KSharedConfig::openConfig("kdeglobals", KConfig::IncludeGlobals); + KConfigGroup configGroup(globalConfig, "KDE"); + m_showDeleteCommand->setChecked(configGroup.readEntry("ShowDeleteCommand", false)); + + GeneralSettings* settings = DolphinSettings::instance().generalSettings(); + m_showCopyMoveMenu->setChecked(settings->showCopyMoveMenu()); + m_showZoomSlider->setChecked(settings->showZoomSlider()); + m_showSpaceInfo->setChecked(settings->showSpaceInfo()); + m_browseThroughArchives->setChecked(settings->browseThroughArchives()); + m_renameInline->setChecked(settings->renameInline()); + m_autoExpandFolders->setChecked(settings->autoExpandFolders()); +} + +#include "generalsettingspage.moc" diff --git a/src/settings/generalsettingspage.h b/src/settings/generalsettingspage.h new file mode 100644 index 000000000..4059dc3c6 --- /dev/null +++ b/src/settings/generalsettingspage.h @@ -0,0 +1,64 @@ +/*************************************************************************** + * Copyright (C) 2006 by Peter Penz * + * peter.penz@gmx.at * + * * + * 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 of the License, 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. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ +#ifndef GENERALSETTINGSPAGE_H +#define GENERALSETTINGSPAGE_H + +#include + +class DolphinMainWindow; +class QLineEdit; +class QCheckBox; + +/** + * @brief Page for the 'General' settings of the Dolphin settings dialog. + */ +class GeneralSettingsPage : public SettingsPageBase +{ + Q_OBJECT + +public: + GeneralSettingsPage(DolphinMainWindow* mainWindow, QWidget* parent); + virtual ~GeneralSettingsPage(); + + /** @see SettingsPageBase::applySettings() */ + virtual void applySettings(); + + /** @see SettingsPageBase::restoreDefaults() */ + virtual void restoreDefaults(); + +private: + void loadSettings(); + +private: + QCheckBox* m_confirmMoveToTrash; + QCheckBox* m_confirmDelete; + + QCheckBox* m_showDeleteCommand; + QCheckBox* m_showCopyMoveMenu; + + QCheckBox* m_showZoomSlider; + QCheckBox* m_showSpaceInfo; + + QCheckBox* m_browseThroughArchives; + QCheckBox* m_renameInline; + QCheckBox* m_autoExpandFolders; +}; + +#endif diff --git a/src/settings/generalviewsettingspage.cpp b/src/settings/generalviewsettingspage.cpp new file mode 100644 index 000000000..acea9649c --- /dev/null +++ b/src/settings/generalviewsettingspage.cpp @@ -0,0 +1,201 @@ +/*************************************************************************** + * Copyright (C) 2006 by Peter Penz * + * * + * 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 of the License, 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. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#include "generalviewsettingspage.h" +#include "dolphinmainwindow.h" +#include "settings/dolphinsettings.h" +#include "dolphinviewcontainer.h" +#include "viewproperties.h" + +#include "dolphin_generalsettings.h" + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +GeneralViewSettingsPage::GeneralViewSettingsPage(const KUrl& url, + QWidget* parent) : + ViewSettingsPageBase(parent), + m_url(url), + m_localProps(0), + m_globalProps(0), + m_maxPreviewSize(0), + m_spinBox(0), + m_useFileThumbnails(0), + m_showSelectionToggle(0), + m_showToolTips(0) +{ + const int spacing = KDialog::spacingHint(); + const int margin = KDialog::marginHint(); + const QSizePolicy sizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); + + setSpacing(spacing); + setMargin(margin); + + QGroupBox* propsBox = new QGroupBox(i18nc("@title:group", "View Properties"), this); + + m_localProps = new QRadioButton(i18nc("@option:radio", "Remember view properties for each folder"), propsBox); + connect(m_localProps, SIGNAL(toggled(bool)), this, SIGNAL(changed())); + + m_globalProps = new QRadioButton(i18nc("@option:radio", "Use common view properties for all folders"), propsBox); + connect(m_globalProps, SIGNAL(toggled(bool)), this, SIGNAL(changed())); + + QVBoxLayout* propsBoxLayout = new QVBoxLayout(propsBox); + propsBoxLayout->addWidget(m_localProps); + propsBoxLayout->addWidget(m_globalProps); + + // create 'File Previews' box + QGroupBox* previewBox = new QGroupBox(i18nc("@title:group", "File Previews"), this); + + KHBox* vBox = new KHBox(previewBox); + vBox->setSpacing(spacing); + + new QLabel(i18nc("@label:slider", "Maximum file size:"), vBox); + m_maxPreviewSize = new QSlider(Qt::Horizontal, vBox); + + m_spinBox = new QSpinBox(vBox); + + connect(m_maxPreviewSize, SIGNAL(valueChanged(int)), + m_spinBox, SLOT(setValue(int))); + connect(m_spinBox, SIGNAL(valueChanged(int)), + m_maxPreviewSize, SLOT(setValue(int))); + + connect(m_maxPreviewSize, SIGNAL(valueChanged(int)), + this, SIGNAL(changed())); + connect(m_spinBox, SIGNAL(valueChanged(int)), + this, SIGNAL(changed())); + + m_useFileThumbnails = new QCheckBox(i18nc("@option:check", "Use thumbnails embedded in files"), previewBox); + connect(m_useFileThumbnails, SIGNAL(toggled(bool)), this, SIGNAL(changed())); + + QVBoxLayout* previewBoxLayout = new QVBoxLayout(previewBox); + previewBoxLayout->addWidget(vBox); + previewBoxLayout->addWidget(m_useFileThumbnails); + + m_showSelectionToggle = new QCheckBox(i18nc("@option:check", "Show selection marker"), this); + connect(m_showSelectionToggle, SIGNAL(toggled(bool)), this, SIGNAL(changed())); + + m_showToolTips = new QCheckBox(i18nc("@option:check", "Show tooltips"), this); + connect(m_showToolTips, SIGNAL(toggled(bool)), this, SIGNAL(changed())); + + // Add a dummy widget with no restriction regarding + // a vertical resizing. This assures that the dialog layout + // is not stretched vertically. + new QWidget(this); + + loadSettings(); +} + + +GeneralViewSettingsPage::~GeneralViewSettingsPage() +{ +} + +void GeneralViewSettingsPage::applySettings() +{ + ViewProperties props(m_url); // read current view properties + + const bool useGlobalProps = m_globalProps->isChecked(); + + GeneralSettings* settings = DolphinSettings::instance().generalSettings(); + settings->setGlobalViewProps(useGlobalProps); + + if (useGlobalProps) { + // Remember the global view properties by applying the current view properties. + // It is important that GeneralSettings::globalViewProps() is set before + // the class ViewProperties is used, as ViewProperties uses this setting + // to find the destination folder for storing the view properties. + ViewProperties globalProps(m_url); + globalProps.setDirProperties(props); + } + + KConfigGroup globalConfig(KGlobal::config(), "PreviewSettings"); + const int byteCount = m_maxPreviewSize->value() * 1024 * 1024; // value() returns size in MB + globalConfig.writeEntry("MaximumSize", + byteCount, + KConfigBase::Normal | KConfigBase::Global); + globalConfig.writeEntry("UseFileThumbnails", + m_useFileThumbnails->isChecked(), + KConfigBase::Normal | KConfigBase::Global); + globalConfig.sync(); + + settings->setShowSelectionToggle(m_showSelectionToggle->isChecked()); + settings->setShowToolTips(m_showToolTips->isChecked()); +} + +void GeneralViewSettingsPage::restoreDefaults() +{ + GeneralSettings* settings = DolphinSettings::instance().generalSettings(); + settings->setDefaults(); + loadSettings(); +} + +void GeneralViewSettingsPage::loadSettings() +{ + GeneralSettings* settings = DolphinSettings::instance().generalSettings(); + if (settings->globalViewProps()) { + m_globalProps->setChecked(true); + } else { + m_localProps->setChecked(true); + } + + const int min = 1; // MB + const int max = 100; // MB + m_maxPreviewSize->setRange(min, max); + m_maxPreviewSize->setPageStep(10); + m_maxPreviewSize->setSingleStep(1); + m_maxPreviewSize->setTickPosition(QSlider::TicksBelow); + + KConfigGroup globalConfig(KGlobal::config(), "PreviewSettings"); + // TODO: The default value of 5 MB must match with the default value inside + // kdelibs/kio/kio/previewjob.cpp. Maybe a static getter method in PreviewJob + // should be added for getting the default size? + const int maxByteSize = globalConfig.readEntry("MaximumSize", 5 * 1024 * 1024 /* 5 MB */); + int maxMByteSize = maxByteSize / (1024 * 1024); + if (maxMByteSize < 1) { + maxMByteSize = 1; + } else if (maxMByteSize > max) { + maxMByteSize = max; + } + + m_spinBox->setRange(min, max); + m_spinBox->setSingleStep(1); + m_spinBox->setSuffix(" MB"); + + m_maxPreviewSize->setValue(maxMByteSize); + m_spinBox->setValue(m_maxPreviewSize->value()); + + const bool useFileThumbnails = globalConfig.readEntry("UseFileThumbnails", true); + m_useFileThumbnails->setChecked(useFileThumbnails); + + m_showSelectionToggle->setChecked(settings->showSelectionToggle()); + m_showToolTips->setChecked(settings->showToolTips()); +} + +#include "generalviewsettingspage.moc" diff --git a/src/settings/generalviewsettingspage.h b/src/settings/generalviewsettingspage.h new file mode 100644 index 000000000..b0bd7e005 --- /dev/null +++ b/src/settings/generalviewsettingspage.h @@ -0,0 +1,73 @@ +/*************************************************************************** + * Copyright (C) 2006 by Peter Penz * + * * + * 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 of the License, 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. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#ifndef GENERALVIEWSETTINGSPAGE_H +#define GENERALVIEWSETTINGSPAGE_H + +#include +#include + +class DolphinMainWindow; +class QCheckBox; +class QRadioButton; +class QSlider; +class QSpinBox; + +/** + * @brief Represents the page from the Dolphin Settings which allows + * to modify general settings for the view modes. + */ +class GeneralViewSettingsPage : public ViewSettingsPageBase +{ + Q_OBJECT + +public: + /** + * @param url URL of the currently shown directory, which is used + * to read the viewproperties. + * @param parent Parent widget of the settings page. + */ + GeneralViewSettingsPage(const KUrl& url, QWidget* parent); + virtual ~GeneralViewSettingsPage(); + + /** + * Applies the general settings for the view modes + * The settings are persisted automatically when + * closing Dolphin. + */ + virtual void applySettings(); + + /** Restores the settings to default values. */ + virtual void restoreDefaults(); + +private: + void loadSettings(); + +private: + KUrl m_url; + QRadioButton* m_localProps; + QRadioButton* m_globalProps; + QSlider* m_maxPreviewSize; + QSpinBox* m_spinBox; + QCheckBox* m_useFileThumbnails; + QCheckBox* m_showSelectionToggle; + QCheckBox* m_showToolTips; +}; + +#endif diff --git a/src/settings/iconsizegroupbox.cpp b/src/settings/iconsizegroupbox.cpp new file mode 100644 index 000000000..82698e7b7 --- /dev/null +++ b/src/settings/iconsizegroupbox.cpp @@ -0,0 +1,116 @@ +/*************************************************************************** + * Copyright (C) 2008 by Peter Penz * + * * + * 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 of the License, 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. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#include "iconsizegroupbox.h" + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "zoomlevelinfo.h" + +IconSizeGroupBox::IconSizeGroupBox(QWidget* parent) : + QGroupBox(i18nc("@title:group", "Icon Size"), parent), + m_defaultSizeSlider(0), + m_previewSizeSlider(0) +{ + QLabel* defaultLabel = new QLabel(i18nc("@label:listbox", "Default:"), this); + m_defaultSizeSlider = new QSlider(Qt::Horizontal, this); + m_defaultSizeSlider->setPageStep(1); + m_defaultSizeSlider->setTickPosition(QSlider::TicksBelow); + connect(m_defaultSizeSlider, SIGNAL(sliderMoved(int)), + this, SLOT(slotDefaultSliderMoved(int))); + + QLabel* previewLabel = new QLabel(i18nc("@label:listbox", "Preview:"), this); + m_previewSizeSlider = new QSlider(Qt::Horizontal, this); + m_previewSizeSlider->setPageStep(1); + m_previewSizeSlider->setTickPosition(QSlider::TicksBelow); + connect(m_previewSizeSlider, SIGNAL(sliderMoved(int)), + this, SLOT(slotPreviewSliderMoved(int))); + + QGridLayout* layout = new QGridLayout(this); + layout->addWidget(defaultLabel, 0, 0, Qt::AlignRight); + layout->addWidget(m_defaultSizeSlider, 0, 1); + layout->addWidget(previewLabel, 1, 0, Qt::AlignRight); + layout->addWidget(m_previewSizeSlider, 1, 1); +} + +IconSizeGroupBox::~IconSizeGroupBox() +{ +} + +void IconSizeGroupBox::setDefaultSizeRange(int min, int max) +{ + m_defaultSizeSlider->setRange(min, max); +} + +void IconSizeGroupBox::setPreviewSizeRange(int min, int max) +{ + m_previewSizeSlider->setRange(min, max); +} + +void IconSizeGroupBox::setDefaultSizeValue(int value) +{ + m_defaultSizeSlider->setValue(value); +} + +int IconSizeGroupBox::defaultSizeValue() const +{ + return m_defaultSizeSlider->value(); +} + +void IconSizeGroupBox::setPreviewSizeValue(int value) +{ + m_previewSizeSlider->setValue(value); +} + +int IconSizeGroupBox::previewSizeValue() const +{ + return m_previewSizeSlider->value(); +} + +void IconSizeGroupBox::slotDefaultSliderMoved(int value) +{ + showToolTip(m_defaultSizeSlider, value); + emit defaultSizeChanged(value); +} + +void IconSizeGroupBox::slotPreviewSliderMoved(int value) +{ + showToolTip(m_previewSizeSlider, value); + emit previewSizeChanged(value); +} + +void IconSizeGroupBox::showToolTip(QSlider* slider, int value) +{ + const int size = ZoomLevelInfo::iconSizeForZoomLevel(value); + slider->setToolTip(i18ncp("@info:tooltip", "Size: 1 pixel", "Size: %1 pixels", size)); + QPoint global = slider->rect().topLeft(); + global.ry() += slider->height() / 2; + QHelpEvent toolTipEvent(QEvent::ToolTip, QPoint(0, 0), slider->mapToGlobal(global)); + QApplication::sendEvent(slider, &toolTipEvent); +} + +#include "iconsizegroupbox.moc" diff --git a/src/settings/iconsizegroupbox.h b/src/settings/iconsizegroupbox.h new file mode 100644 index 000000000..3ec51c3a5 --- /dev/null +++ b/src/settings/iconsizegroupbox.h @@ -0,0 +1,66 @@ +/*************************************************************************** + * Copyright (C) 2008 by Peter Penz * + * * + * 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 of the License, 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. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#ifndef ICONSIZEGROUPBOX_H +#define ICONSIZEGROUPBOX_H + +#include + +class QSlider; + +/** + * @short Provides a group box for adjusting the icon sizes. + * + * It is possible to adjust the default icon size and the icon + * size when previews are used. + */ +class IconSizeGroupBox : public QGroupBox +{ + Q_OBJECT + +public: + explicit IconSizeGroupBox(QWidget* parent); + virtual ~IconSizeGroupBox(); + + void setDefaultSizeRange(int min, int max); + void setPreviewSizeRange(int min, int max); + + void setDefaultSizeValue(int value); + int defaultSizeValue() const; + + void setPreviewSizeValue(int value); + int previewSizeValue() const; + +signals: + void defaultSizeChanged(int value); + void previewSizeChanged(int value); + +private slots: + void slotDefaultSliderMoved(int value); + void slotPreviewSliderMoved(int value); + +private: + void showToolTip(QSlider* slider, int value); + +private: + QSlider* m_defaultSizeSlider; + QSlider* m_previewSizeSlider; +}; + +#endif diff --git a/src/settings/iconsviewsettingspage.cpp b/src/settings/iconsviewsettingspage.cpp new file mode 100644 index 000000000..2acb4cd60 --- /dev/null +++ b/src/settings/iconsviewsettingspage.cpp @@ -0,0 +1,243 @@ +/*************************************************************************** + * Copyright (C) 2006 by Peter Penz * + * * + * 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 of the License, 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. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#include "iconsviewsettingspage.h" + +#include "dolphinfontrequester.h" +#include "settings/dolphinsettings.h" +#include "iconsizegroupbox.h" +#include "zoomlevelinfo.h" + +#include "dolphin_iconsmodesettings.h" + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +IconsViewSettingsPage::IconsViewSettingsPage(QWidget* parent) : + ViewSettingsPageBase(parent), + m_iconSizeGroupBox(0), + m_textWidthBox(0), + m_fontRequester(0), + m_textlinesCountBox(0), + m_arrangementBox(0), + m_gridSpacingBox(0) +{ + const int spacing = KDialog::spacingHint(); + const int margin = KDialog::marginHint(); + const QSizePolicy sizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); + + setSpacing(spacing); + setMargin(margin); + + // Create "Icon" properties + m_iconSizeGroupBox = new IconSizeGroupBox(this); + m_iconSizeGroupBox->setSizePolicy(sizePolicy); + + const int min = ZoomLevelInfo::minimumLevel(); + const int max = ZoomLevelInfo::maximumLevel(); + m_iconSizeGroupBox->setDefaultSizeRange(min, max); + m_iconSizeGroupBox->setPreviewSizeRange(min, max); + + connect(m_iconSizeGroupBox, SIGNAL(defaultSizeChanged(int)), + this, SIGNAL(changed())); + connect(m_iconSizeGroupBox, SIGNAL(previewSizeChanged(int)), + this, SIGNAL(changed())); + + // create 'Text' group for selecting the font, the number of lines + // and the text width + QGroupBox* textGroup = new QGroupBox(i18nc("@title:group", "Text"), this); + textGroup->setSizePolicy(sizePolicy); + + QLabel* fontLabel = new QLabel(i18nc("@label:listbox", "Font:"), textGroup); + m_fontRequester = new DolphinFontRequester(textGroup); + connect(m_fontRequester, SIGNAL(changed()), this, SIGNAL(changed())); + + QLabel* textlinesCountLabel = new QLabel(i18nc("@label:textbox", "Number of lines:"), textGroup); + m_textlinesCountBox = new QSpinBox(textGroup); + m_textlinesCountBox->setMinimum(1); + m_textlinesCountBox->setMaximum(5); + connect(m_textlinesCountBox, SIGNAL(valueChanged(int)), this, SIGNAL(changed())); + + QLabel* textWidthLabel = new QLabel(i18nc("@label:listbox", "Text width:"), textGroup); + m_textWidthBox = new KComboBox(textGroup); + m_textWidthBox->addItem(i18nc("@item:inlistbox Text width", "Small")); + m_textWidthBox->addItem(i18nc("@item:inlistbox Text width", "Medium")); + m_textWidthBox->addItem(i18nc("@item:inlistbox Text width", "Large")); + m_textWidthBox->addItem(i18nc("@item:inlistbox Text width", "Huge")); + connect(m_textWidthBox, SIGNAL(activated(int)), this, SIGNAL(changed())); + + QGridLayout* textGroupLayout = new QGridLayout(textGroup); + textGroupLayout->addWidget(fontLabel, 0, 0, Qt::AlignRight); + textGroupLayout->addWidget(m_fontRequester, 0, 1); + textGroupLayout->addWidget(textlinesCountLabel, 1, 0, Qt::AlignRight); + textGroupLayout->addWidget(m_textlinesCountBox, 1, 1); + textGroupLayout->addWidget(textWidthLabel, 2, 0, Qt::AlignRight); + textGroupLayout->addWidget(m_textWidthBox, 2, 1); + + // create the 'Grid' group for selecting the arrangement and the grid spacing + QGroupBox* gridGroup = new QGroupBox(i18nc("@title:group", "Grid"), this); + gridGroup->setSizePolicy(sizePolicy); + + QLabel* arrangementLabel = new QLabel(i18nc("@label:listbox", "Arrangement:"), gridGroup); + m_arrangementBox = new KComboBox(gridGroup); + m_arrangementBox->addItem(i18nc("@item:inlistbox Arrangement", "Columns")); + m_arrangementBox->addItem(i18nc("@item:inlistbox Arrangement", "Rows")); + connect(m_arrangementBox, SIGNAL(activated(int)), this, SIGNAL(changed())); + + QLabel* gridSpacingLabel = new QLabel(i18nc("@label:listbox", "Grid spacing:"), gridGroup); + m_gridSpacingBox = new KComboBox(gridGroup); + m_gridSpacingBox->addItem(i18nc("@item:inlistbox Grid spacing", "None")); + m_gridSpacingBox->addItem(i18nc("@item:inlistbox Grid spacing", "Small")); + m_gridSpacingBox->addItem(i18nc("@item:inlistbox Grid spacing", "Medium")); + m_gridSpacingBox->addItem(i18nc("@item:inlistbox Grid spacing", "Large")); + connect(m_gridSpacingBox, SIGNAL(activated(int)), this, SIGNAL(changed())); + + QGridLayout* gridGroupLayout = new QGridLayout(gridGroup); + gridGroupLayout->addWidget(arrangementLabel, 0, 0, Qt::AlignRight); + gridGroupLayout->addWidget(m_arrangementBox, 0, 1); + gridGroupLayout->addWidget(gridSpacingLabel, 1, 0, Qt::AlignRight); + gridGroupLayout->addWidget(m_gridSpacingBox, 1, 1); + + // Add a dummy widget with no restriction regarding + // a vertical resizing. This assures that the dialog layout + // is not stretched vertically. + new QWidget(this); + + loadSettings(); +} + +IconsViewSettingsPage::~IconsViewSettingsPage() +{ +} + +void IconsViewSettingsPage::applySettings() +{ + IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings(); + + const int iconSize = ZoomLevelInfo::iconSizeForZoomLevel(m_iconSizeGroupBox->defaultSizeValue()); + const int previewSize = ZoomLevelInfo::iconSizeForZoomLevel(m_iconSizeGroupBox->previewSizeValue()); + settings->setIconSize(iconSize); + settings->setPreviewSize(previewSize); + + const QFont font = m_fontRequester->font(); + const int fontHeight = QFontMetrics(font).height(); + + const int arrangement = (m_arrangementBox->currentIndex() == 0) ? + QListView::LeftToRight : + QListView::TopToBottom; + settings->setArrangement(arrangement); + + const int numberOfTextlines = m_textlinesCountBox->value(); + + const int defaultSize = settings->iconSize(); + int itemWidth = defaultSize; + int itemHeight = defaultSize; + const int textSizeIndex = m_textWidthBox->currentIndex(); + if (arrangement == QListView::TopToBottom) { + itemWidth += TopToBottomBase + textSizeIndex * TopToBottomInc; + itemHeight += fontHeight * numberOfTextlines + 10; + } else { + itemWidth += LeftToRightBase + textSizeIndex * LeftToRightInc; + } + + settings->setItemWidth(itemWidth); + settings->setItemHeight(itemHeight); + + settings->setUseSystemFont(m_fontRequester->mode() == DolphinFontRequester::SystemFont); + settings->setFontFamily(font.family()); + settings->setFontSize(font.pointSize()); + settings->setItalicFont(font.italic()); + settings->setFontWeight(font.weight()); + + settings->setNumberOfTextlines(numberOfTextlines); + + const int index = m_gridSpacingBox->currentIndex(); + if (index == 0) { + // No grid spacing + settings->setGridSpacing(0); + } else { + settings->setGridSpacing(GridSpacingBase + (index - 1) * GridSpacingInc); + } +} + +void IconsViewSettingsPage::restoreDefaults() +{ + IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings(); + settings->setDefaults(); + loadSettings(); +} + +void IconsViewSettingsPage::loadSettings() +{ + IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings(); + + const QSize iconSize(settings->iconSize(), settings->iconSize()); + const int iconSizeValue = ZoomLevelInfo::zoomLevelForIconSize(iconSize); + m_iconSizeGroupBox->setDefaultSizeValue(iconSizeValue); + + const QSize previewSize(settings->previewSize(), settings->previewSize()); + const int previewSizeValue = ZoomLevelInfo::zoomLevelForIconSize(previewSize); + m_iconSizeGroupBox->setPreviewSizeValue(previewSizeValue); + + if (settings->useSystemFont()) { + m_fontRequester->setMode(DolphinFontRequester::SystemFont); + } else { + QFont font(settings->fontFamily(), + settings->fontSize()); + font.setItalic(settings->italicFont()); + font.setWeight(settings->fontWeight()); + m_fontRequester->setMode(DolphinFontRequester::CustomFont); + m_fontRequester->setCustomFont(font); + } + + m_textlinesCountBox->setValue(settings->numberOfTextlines()); + + const bool leftToRightArrangement = (settings->arrangement() == QListView::LeftToRight); + int textWidthIndex = 0; + const int remainingWidth = settings->itemWidth() - settings->iconSize(); + if (leftToRightArrangement) { + textWidthIndex = (remainingWidth - LeftToRightBase) / LeftToRightInc; + } else { + textWidthIndex = (remainingWidth - TopToBottomBase) / TopToBottomInc; + } + // ensure that chosen index is always valid + textWidthIndex = qMax(textWidthIndex, 0); + textWidthIndex = qMin(textWidthIndex, m_textWidthBox->count() - 1); + + m_textWidthBox->setCurrentIndex(textWidthIndex); + m_arrangementBox->setCurrentIndex(leftToRightArrangement ? 0 : 1); + + const int spacing = settings->gridSpacing(); + const int index = (spacing <= 0) ? 0 : 1 + (spacing - GridSpacingBase) / GridSpacingInc; + m_gridSpacingBox->setCurrentIndex(index); +} + +#include "iconsviewsettingspage.moc" diff --git a/src/settings/iconsviewsettingspage.h b/src/settings/iconsviewsettingspage.h new file mode 100644 index 000000000..c30ade673 --- /dev/null +++ b/src/settings/iconsviewsettingspage.h @@ -0,0 +1,88 @@ +/*************************************************************************** + * Copyright (C) 2006 by Peter Penz * + * * + * 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 of the License, 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. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#ifndef ICONSVIEWSETTINGSPAGE_H +#define ICONSVIEWSETTINGSPAGE_H + +#include +#include + +class DolphinFontRequester; +class IconSizeGroupBox; +class QCheckBox; +class KComboBox; +class QSpinBox; + +/** + * @brief Tab page for the 'Icons Mode' and 'Previews Mode' settings + * of the Dolphin settings dialog. + * + * Allows to set: + * - icon size + * - preview size + * - text width + * - grid spacing + * - font + * - number of text lines + * - arrangement + * + * @see DolphinIconsViewSettings + */ +class IconsViewSettingsPage : public ViewSettingsPageBase +{ + Q_OBJECT + +public: + IconsViewSettingsPage(QWidget* parent); + virtual ~IconsViewSettingsPage(); + + /** + * Applies the settings for the icons view. + * The settings are persisted automatically when + * closing Dolphin. + */ + virtual void applySettings(); + + /** Restores the settings to default values. */ + virtual void restoreDefaults(); + +private: + void loadSettings(); + +private: + enum + { + GridSpacingBase = 8, + GridSpacingInc = 12, + LeftToRightBase = 128, + LeftToRightInc = 64, + TopToBottomBase = 32, + TopToBottomInc = 32 + }; + + IconSizeGroupBox* m_iconSizeGroupBox; + KComboBox* m_textWidthBox; + DolphinFontRequester* m_fontRequester; + QSpinBox* m_textlinesCountBox; + + KComboBox* m_arrangementBox; + KComboBox* m_gridSpacingBox; +}; + +#endif diff --git a/src/settings/settingspagebase.cpp b/src/settings/settingspagebase.cpp new file mode 100644 index 000000000..6f8dcbfb6 --- /dev/null +++ b/src/settings/settingspagebase.cpp @@ -0,0 +1,31 @@ +/*************************************************************************** + * Copyright (C) 2006 by Peter Penz * + * peter.penz@gmx.at * + * * + * 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 of the License, 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. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#include "settingspagebase.h" + +SettingsPageBase::SettingsPageBase(QWidget* parent) : + QWidget(parent) +{} + +SettingsPageBase::~SettingsPageBase() +{} + + +#include "settingspagebase.moc" diff --git a/src/settings/settingspagebase.h b/src/settings/settingspagebase.h new file mode 100644 index 000000000..19d4cf1f0 --- /dev/null +++ b/src/settings/settingspagebase.h @@ -0,0 +1,56 @@ +/*************************************************************************** + * Copyright (C) 2006 by Peter Penz * + * peter.penz@gmx.at * + * * + * 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 of the License, 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. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#ifndef SETTINGSPAGEBASE_H +#define SETTINGSPAGEBASE_H + +#include + +/** + * @brief Base class for the settings pages of the Dolphin settings dialog. + * + * @author Peter Penz + */ +class SettingsPageBase : public QWidget +{ + Q_OBJECT + +public: + explicit SettingsPageBase(QWidget* parent); + virtual ~SettingsPageBase(); + + /** + * Must be implemented by a derived class to + * persistently store the settings. + */ + virtual void applySettings() = 0; + + /** + * Must be implemented by a derived class to + * restored the settings to default values. + */ + virtual void restoreDefaults() = 0; + +signals: + /** Is emitted if a setting has been changed. */ + void changed(); +}; + +#endif diff --git a/src/settings/startupsettingspage.cpp b/src/settings/startupsettingspage.cpp new file mode 100644 index 000000000..767fcab66 --- /dev/null +++ b/src/settings/startupsettingspage.cpp @@ -0,0 +1,169 @@ +/*************************************************************************** + * Copyright (C) 2008 by Peter Penz * + * * + * 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 of the License, 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. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#include "startupsettingspage.h" + +#include "settings/dolphinsettings.h" +#include "dolphinmainwindow.h" +#include "dolphinview.h" +#include "dolphinviewcontainer.h" + +#include "dolphin_generalsettings.h" + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +StartupSettingsPage::StartupSettingsPage(DolphinMainWindow* mainWin, QWidget* parent) : + SettingsPageBase(parent), + m_mainWindow(mainWin), + m_homeUrl(0), + m_splitView(0), + m_editableUrl(0), + m_showFullPath(0), + m_filterBar(0) +{ + const int spacing = KDialog::spacingHint(); + + QVBoxLayout* topLayout = new QVBoxLayout(this); + KVBox* vBox = new KVBox(this); + vBox->setSpacing(spacing); + + // create 'Home URL' editor + QGroupBox* homeBox = new QGroupBox(i18nc("@title:group", "Home Folder"), vBox); + + KHBox* homeUrlBox = new KHBox(homeBox); + homeUrlBox->setSpacing(spacing); + + new QLabel(i18nc("@label:textbox", "Location:"), homeUrlBox); + m_homeUrl = new KLineEdit(homeUrlBox); + m_homeUrl->setClearButtonShown(true); + + QPushButton* selectHomeUrlButton = new QPushButton(KIcon("folder-open"), QString(), homeUrlBox); + connect(selectHomeUrlButton, SIGNAL(clicked()), + this, SLOT(selectHomeUrl())); + + KHBox* buttonBox = new KHBox(homeBox); + buttonBox->setSpacing(spacing); + + QPushButton* useCurrentButton = new QPushButton(i18nc("@action:button", "Use Current Location"), buttonBox); + connect(useCurrentButton, SIGNAL(clicked()), + this, SLOT(useCurrentLocation())); + QPushButton* useDefaultButton = new QPushButton(i18nc("@action:button", "Use Default Location"), buttonBox); + connect(useDefaultButton, SIGNAL(clicked()), + this, SLOT(useDefaultLocation())); + + QVBoxLayout* homeBoxLayout = new QVBoxLayout(homeBox); + homeBoxLayout->addWidget(homeUrlBox); + homeBoxLayout->addWidget(buttonBox); + + // create 'Split view', 'Editable location' and 'Filter bar' checkboxes + m_splitView = new QCheckBox(i18nc("@option:check Startup Settings", "Split view mode"), vBox); + m_editableUrl = new QCheckBox(i18nc("@option:check Startup Settings", "Editable location bar"), vBox); + m_showFullPath = new QCheckBox(i18nc("@option:check Startup Settings", "Show full path inside location bar"), vBox); + m_filterBar = new QCheckBox(i18nc("@option:check Startup Settings", "Show filter bar"), vBox); + connect(m_splitView, SIGNAL(toggled(bool)), this, SIGNAL(changed())); + connect(m_editableUrl, SIGNAL(toggled(bool)), this, SIGNAL(changed())); + connect(m_showFullPath, SIGNAL(toggled(bool)), this, SIGNAL(changed())); + connect(m_filterBar, SIGNAL(toggled(bool)), this, SIGNAL(changed())); + + // Add a dummy widget with no restriction regarding + // a vertical resizing. This assures that the dialog layout + // is not stretched vertically. + new QWidget(vBox); + + topLayout->addWidget(vBox); + + loadSettings(); + + // it's important connecting 'textChanged' after loadSettings(), as loadSettings() + // invokes m_homeUrl->setText() + connect(m_homeUrl, SIGNAL(textChanged(const QString&)), this, SIGNAL(changed())); +} + +StartupSettingsPage::~StartupSettingsPage() +{ +} + +void StartupSettingsPage::applySettings() +{ + GeneralSettings* settings = DolphinSettings::instance().generalSettings(); + + const KUrl url(m_homeUrl->text()); + KFileItem fileItem(KFileItem::Unknown, KFileItem::Unknown, url); + if (url.isValid() && fileItem.isDir()) { + settings->setHomeUrl(url.prettyUrl()); + } else { + KMessageBox::error(this, i18nc("@info", "The location for the home folder is invalid and will not be applied.")); + } + + settings->setSplitView(m_splitView->isChecked()); + settings->setEditableUrl(m_editableUrl->isChecked()); + settings->setShowFullPath(m_showFullPath->isChecked()); + settings->setFilterBar(m_filterBar->isChecked()); +} + +void StartupSettingsPage::restoreDefaults() +{ + GeneralSettings* settings = DolphinSettings::instance().generalSettings(); + settings->setDefaults(); + loadSettings(); +} + +void StartupSettingsPage::selectHomeUrl() +{ + const QString homeUrl = m_homeUrl->text(); + KUrl url = KFileDialog::getExistingDirectoryUrl(homeUrl, this); + if (!url.isEmpty()) { + m_homeUrl->setText(url.prettyUrl()); + emit changed(); + } +} + +void StartupSettingsPage::useCurrentLocation() +{ + const DolphinView* view = m_mainWindow->activeViewContainer()->view(); + m_homeUrl->setText(view->url().prettyUrl()); +} + +void StartupSettingsPage::useDefaultLocation() +{ + m_homeUrl->setText(QDir::homePath()); +} + +void StartupSettingsPage::loadSettings() +{ + GeneralSettings* settings = DolphinSettings::instance().generalSettings(); + m_homeUrl->setText(settings->homeUrl()); + m_splitView->setChecked(settings->splitView()); + m_editableUrl->setChecked(settings->editableUrl()); + m_showFullPath->setChecked(settings->showFullPath()); + m_filterBar->setChecked(settings->filterBar()); +} + +#include "startupsettingspage.moc" diff --git a/src/settings/startupsettingspage.h b/src/settings/startupsettingspage.h new file mode 100644 index 000000000..04844f00c --- /dev/null +++ b/src/settings/startupsettingspage.h @@ -0,0 +1,66 @@ +/*************************************************************************** + * Copyright (C) 2008 by Peter Penz * + * * + * 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 of the License, 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. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ +#ifndef STARTUPSETTINGSPAGE_H +#define STARTUPSETTINGSPAGE_H + +#include + +class DolphinMainWindow; +class KLineEdit; +class QCheckBox; + +/** + * @brief Page for the 'Startup' settings of the Dolphin settings dialog. + * + * The startup settings allow to set the home URL and to configure the + * state of the view mode, split mode and the filter bar when starting Dolphin. + */ +class StartupSettingsPage : public SettingsPageBase +{ + Q_OBJECT + +public: + StartupSettingsPage(DolphinMainWindow* mainWindow, QWidget* parent); + virtual ~StartupSettingsPage(); + + /** @see SettingsPageBase::applySettings() */ + virtual void applySettings(); + + /** @see SettingsPageBase::restoreDefaults() */ + virtual void restoreDefaults(); + +private slots: + void selectHomeUrl(); + void useCurrentLocation(); + void useDefaultLocation(); + +private: + void loadSettings(); + +private: + DolphinMainWindow* m_mainWindow; + KLineEdit* m_homeUrl; + + QCheckBox* m_splitView; + QCheckBox* m_editableUrl; + QCheckBox* m_showFullPath; + QCheckBox* m_filterBar; +}; + +#endif diff --git a/src/settings/viewpropertiesdialog.cpp b/src/settings/viewpropertiesdialog.cpp new file mode 100644 index 000000000..700bdb90b --- /dev/null +++ b/src/settings/viewpropertiesdialog.cpp @@ -0,0 +1,405 @@ +/*************************************************************************** + * Copyright (C) 2006 by Peter Penz * + * peter.penz@gmx.at * + * * + * 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 of the License, 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. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#include "viewpropertiesdialog.h" + +#include "additionalinfodialog.h" +#include "dolphinview.h" +#include "settings/dolphinsettings.h" +#include "dolphinsortfilterproxymodel.h" +#include "dolphin_generalsettings.h" +#include "dolphin_iconsmodesettings.h" +#include "viewproperties.h" +#include "viewpropsprogressinfo.h" + +#include +#ifdef HAVE_NEPOMUK +#include +#endif + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +ViewPropertiesDialog::ViewPropertiesDialog(DolphinView* dolphinView) : + KDialog(dolphinView), + m_isDirty(false), + m_dolphinView(dolphinView), + m_viewProps(0), + m_viewMode(0), + m_sortOrder(0), + m_sorting(0), + m_showPreview(0), + m_showInGroups(0), + m_showHiddenFiles(0), + m_additionalInfo(0), + m_applyToCurrentFolder(0), + m_applyToSubFolders(0), + m_applyToAllFolders(0), + m_useAsDefault(0) +{ + Q_ASSERT(dolphinView != 0); + const bool useGlobalViewProps = DolphinSettings::instance().generalSettings()->globalViewProps(); + + setCaption(i18nc("@title:window", "View Properties")); + setButtons(KDialog::Ok | KDialog::Cancel | KDialog::Apply); + + const KUrl& url = dolphinView->url(); + m_viewProps = new ViewProperties(url); + m_viewProps->setAutoSaveEnabled(false); + + QWidget* main = new QWidget(); + QVBoxLayout* topLayout = new QVBoxLayout(); + + // create 'Properties' group containing view mode, sorting, sort order and show hidden files + QWidget* propsBox = main; + if (!useGlobalViewProps) { + propsBox = new QGroupBox(i18nc("@title:group", "Properties"), main); + } + + QWidget* propsGrid = new QWidget(); + + QLabel* viewModeLabel = new QLabel(i18nc("@label:listbox", "View mode:"), propsGrid); + m_viewMode = new KComboBox(propsGrid); + m_viewMode->addItem(KIcon("view-list-icons"), i18nc("@item:inlistbox", "Icons")); + m_viewMode->addItem(KIcon("view-list-details"), i18nc("@item:inlistbox", "Details")); + m_viewMode->addItem(KIcon("view-file-columns"), i18nc("@item:inlistbox", "Column")); + + QLabel* sortingLabel = new QLabel(i18nc("@label:listbox", "Sorting:"), propsGrid); + QWidget* sortingBox = new QWidget(propsGrid); + + m_sortOrder = new KComboBox(sortingBox); + m_sortOrder->addItem(i18nc("@item:inlistbox Sort", "Ascending")); + m_sortOrder->addItem(i18nc("@item:inlistbox Sort", "Descending")); + + m_sorting = new KComboBox(sortingBox); + m_sorting->addItem(i18nc("@item:inlistbox Sort", "By Name")); + m_sorting->addItem(i18nc("@item:inlistbox Sort", "By Size")); + m_sorting->addItem(i18nc("@item:inlistbox Sort", "By Date")); + m_sorting->addItem(i18nc("@item:inlistbox Sort", "By Permissions")); + m_sorting->addItem(i18nc("@item:inlistbox Sort", "By Owner")); + m_sorting->addItem(i18nc("@item:inlistbox Sort", "By Group")); + m_sorting->addItem(i18nc("@item:inlistbox Sort", "By Type")); +#ifdef HAVE_NEPOMUK + // TODO: Hided "sort by rating" and "sort by tags" as without caching the performance + // is too slow currently (Nepomuk will support caching in future releases). + // + // if (!Nepomuk::ResourceManager::instance()->init()) { + // m_sorting->addItem(i18nc("@item:inlistbox Sort", "By Rating")); + // m_sorting->addItem(i18nc("@item:inlistbox Sort", "By Tags")); + // } +#endif + m_showPreview = new QCheckBox(i18nc("@option:check", "Show preview"), propsBox); + m_showInGroups = new QCheckBox(i18nc("@option:check", "Show in groups"), propsBox); + m_showHiddenFiles = new QCheckBox(i18nc("@option:check", "Show hidden files"), propsBox); + + m_additionalInfo = new QPushButton(i18nc("@action:button", "Additional Information"), propsBox); + + QHBoxLayout* sortingLayout = new QHBoxLayout(); + sortingLayout->setMargin(0); + sortingLayout->addWidget(m_sortOrder); + sortingLayout->addWidget(m_sorting); + sortingBox->setLayout(sortingLayout); + + QGridLayout* propsGridLayout = new QGridLayout(propsGrid); + propsGridLayout->addWidget(viewModeLabel, 0, 0, Qt::AlignRight); + propsGridLayout->addWidget(m_viewMode, 0, 1); + propsGridLayout->addWidget(sortingLabel, 1, 0, Qt::AlignRight); + propsGridLayout->addWidget(sortingBox, 1, 1); + + QVBoxLayout* propsBoxLayout = new QVBoxLayout(propsBox); + propsBoxLayout->addWidget(propsGrid); + propsBoxLayout->addWidget(m_showPreview); + propsBoxLayout->addWidget(m_showInGroups); + propsBoxLayout->addWidget(m_showHiddenFiles); + propsBoxLayout->addWidget(m_additionalInfo); + + topLayout->addWidget(propsBox); + + connect(m_viewMode, SIGNAL(activated(int)), + this, SLOT(slotViewModeChanged(int))); + connect(m_sorting, SIGNAL(activated(int)), + this, SLOT(slotSortingChanged(int))); + connect(m_sortOrder, SIGNAL(activated(int)), + this, SLOT(slotSortOrderChanged(int))); + connect(m_additionalInfo, SIGNAL(clicked()), + this, SLOT(configureAdditionalInfo())); + connect(m_showPreview, SIGNAL(clicked()), + this, SLOT(slotShowPreviewChanged())); + connect(m_showInGroups, SIGNAL(clicked()), + this, SLOT(slotCategorizedSortingChanged())); + connect(m_showHiddenFiles, SIGNAL(clicked()), + this, SLOT(slotShowHiddenFilesChanged())); + + connect(this, SIGNAL(okClicked()), this, SLOT(slotOk())); + connect(this, SIGNAL(applyClicked()), this, SLOT(slotApply())); + + // Only show the following settings if the view properties are remembered + // for each directory: + if (!useGlobalViewProps) { + // create 'Apply View Properties To' group + QGroupBox* applyBox = new QGroupBox(i18nc("@title:group", "Apply View Properties To"), main); + + m_applyToCurrentFolder = new QRadioButton(i18nc("@option:radio Apply View Properties To", + "Current folder"), applyBox); + m_applyToCurrentFolder->setChecked(true); + m_applyToSubFolders = new QRadioButton(i18nc("@option:radio Apply View Properties To", + "Current folder including all sub folders"), applyBox); + m_applyToAllFolders = new QRadioButton(i18nc("@option:radio Apply View Properties To", + "All folders"), applyBox); + + QButtonGroup* applyGroup = new QButtonGroup(this); + applyGroup->addButton(m_applyToCurrentFolder); + applyGroup->addButton(m_applyToSubFolders); + applyGroup->addButton(m_applyToAllFolders); + + QVBoxLayout* applyBoxLayout = new QVBoxLayout(applyBox); + applyBoxLayout->addWidget(m_applyToCurrentFolder); + applyBoxLayout->addWidget(m_applyToSubFolders); + applyBoxLayout->addWidget(m_applyToAllFolders); + + m_useAsDefault = new QCheckBox(i18nc("@option:check", "Use as default for new folders"), main); + + topLayout->addWidget(applyBox); + topLayout->addWidget(m_useAsDefault); + + connect(m_applyToCurrentFolder, SIGNAL(clicked()), + this, SLOT(markAsDirty())); + connect(m_applyToSubFolders, SIGNAL(clicked()), + this, SLOT(markAsDirty())); + connect(m_applyToAllFolders, SIGNAL(clicked()), + this, SLOT(markAsDirty())); + connect(m_useAsDefault, SIGNAL(clicked()), + this, SLOT(markAsDirty())); + } + + main->setLayout(topLayout); + setMainWidget(main); + + const KConfigGroup dialogConfig(KSharedConfig::openConfig("dolphinrc"), + "ViewPropertiesDialog"); + restoreDialogSize(dialogConfig); + + loadSettings(); +} + +ViewPropertiesDialog::~ViewPropertiesDialog() +{ + m_isDirty = false; + delete m_viewProps; + m_viewProps = 0; + + KConfigGroup dialogConfig(KSharedConfig::openConfig("dolphinrc"), + "ViewPropertiesDialog"); + saveDialogSize(dialogConfig, KConfigBase::Persistent); +} + +void ViewPropertiesDialog::slotOk() +{ + applyViewProperties(); + accept(); +} + +void ViewPropertiesDialog::slotApply() +{ + applyViewProperties(); +} + +void ViewPropertiesDialog::slotViewModeChanged(int index) +{ + m_viewProps->setViewMode(static_cast(index)); + m_isDirty = true; + + const DolphinView::Mode mode = m_viewProps->viewMode(); + m_showInGroups->setEnabled(mode == DolphinView::IconsView); + m_additionalInfo->setEnabled(mode != DolphinView::ColumnView); +} + +void ViewPropertiesDialog::slotSortingChanged(int index) +{ + const DolphinView::Sorting sorting = DolphinSortFilterProxyModel::sortingForColumn(index); + m_viewProps->setSorting(sorting); + m_isDirty = true; +} + +void ViewPropertiesDialog::slotSortOrderChanged(int index) +{ + const Qt::SortOrder sortOrder = (index == 0) ? Qt::AscendingOrder : Qt::DescendingOrder; + m_viewProps->setSortOrder(sortOrder); + m_isDirty = true; +} + +void ViewPropertiesDialog::slotCategorizedSortingChanged() +{ + m_viewProps->setCategorizedSorting(m_showInGroups->isChecked()); + m_isDirty = true; +} + +void ViewPropertiesDialog::slotShowPreviewChanged() +{ + const bool show = m_showPreview->isChecked(); + m_viewProps->setShowPreview(show); + m_isDirty = true; +} + +void ViewPropertiesDialog::slotShowHiddenFilesChanged() +{ + const bool show = m_showHiddenFiles->isChecked(); + m_viewProps->setShowHiddenFiles(show); + m_isDirty = true; +} + +void ViewPropertiesDialog::markAsDirty() +{ + m_isDirty = true; +} + +void ViewPropertiesDialog::configureAdditionalInfo() +{ + KFileItemDelegate::InformationList info = m_viewProps->additionalInfo(); + const bool useDefaultInfo = (m_viewProps->viewMode() == DolphinView::DetailsView) && + (info.isEmpty() || info.contains(KFileItemDelegate::NoInformation)); + if (useDefaultInfo) { + // Using the details view without any additional information (-> additional column) + // makes no sense and leads to a usability problem as no viewport area is available + // anymore. Hence as fallback provide at least a size and date column. + info.clear(); + info.append(KFileItemDelegate::Size); + info.append(KFileItemDelegate::ModificationTime); + m_viewProps->setAdditionalInfo(info); + } + + AdditionalInfoDialog dialog(this, info); + if (dialog.exec() == QDialog::Accepted) { + m_viewProps->setAdditionalInfo(dialog.additionalInfo()); + m_isDirty = true; + } +} + +void ViewPropertiesDialog::applyViewProperties() +{ + // if nothing changed in the dialog, we have nothing to apply + if (!m_isDirty) { + return; + } + + const bool applyToSubFolders = (m_applyToSubFolders != 0) && + m_applyToSubFolders->isChecked(); + if (applyToSubFolders) { + const QString text(i18nc("@info", "The view properties of all sub folders will be changed. Do you want to continue?")); + if (KMessageBox::questionYesNo(this, text) == KMessageBox::No) { + return; + } + + ViewPropsProgressInfo* info = new ViewPropsProgressInfo(m_dolphinView, + m_dolphinView->url(), + *m_viewProps); + info->setAttribute(Qt::WA_DeleteOnClose); + info->setWindowModality(Qt::NonModal); + info->show(); + } + + const bool applyToAllFolders = (m_applyToAllFolders != 0) && + m_applyToAllFolders->isChecked(); + + // If the user selected 'Apply To All Folders' the view properties implicitely + // are also used as default for new folders. + const bool useAsDefault = applyToAllFolders || + ((m_useAsDefault != 0) && m_useAsDefault->isChecked()); + if (useAsDefault) { + // For directories where no .directory file is available, the .directory + // file stored for the global view properties is used as fallback. To update + // this file we temporary turn on the global view properties mode. + GeneralSettings* settings = DolphinSettings::instance().generalSettings(); + Q_ASSERT(!settings->globalViewProps()); + + settings->setGlobalViewProps(true); + ViewProperties defaultProps(m_dolphinView->url()); + defaultProps.setDirProperties(*m_viewProps); + defaultProps.save(); + settings->setGlobalViewProps(false); + } + + if (applyToAllFolders) { + const QString text(i18nc("@info", "The view properties of all folders will be changed. Do you want to continue?")); + if (KMessageBox::questionYesNo(this, text) == KMessageBox::No) { + return; + } + + // Updating the global view properties time stamp in the general settings makes + // all existing viewproperties invalid, as they have a smaller time stamp. + GeneralSettings* settings = DolphinSettings::instance().generalSettings(); + settings->setViewPropsTimestamp(QDateTime::currentDateTime()); + } + + m_dolphinView->setMode(m_viewProps->viewMode()); + m_dolphinView->setSorting(m_viewProps->sorting()); + m_dolphinView->setSortOrder(m_viewProps->sortOrder()); + m_dolphinView->setCategorizedSorting(m_viewProps->categorizedSorting()); + m_dolphinView->setAdditionalInfo(m_viewProps->additionalInfo()); + m_dolphinView->setShowPreview(m_viewProps->showPreview()); + m_dolphinView->setShowHiddenFiles(m_viewProps->showHiddenFiles()); + + m_viewProps->save(); + + m_isDirty = false; +} + +void ViewPropertiesDialog::loadSettings() +{ + // load view mode + const int index = static_cast(m_viewProps->viewMode()); + m_viewMode->setCurrentIndex(index); + + // load sort order and sorting + const int sortOrderIndex = (m_viewProps->sortOrder() == Qt::AscendingOrder) ? 0 : 1; + m_sortOrder->setCurrentIndex(sortOrderIndex); + m_sorting->setCurrentIndex(m_viewProps->sorting()); + + const bool enabled = (index == DolphinView::DetailsView) || + (index == DolphinView::IconsView); + m_additionalInfo->setEnabled(enabled); + + // load show preview, show in groups and show hidden files settings + m_showPreview->setChecked(m_viewProps->showPreview()); + + m_showInGroups->setChecked(m_viewProps->categorizedSorting()); + m_showInGroups->setEnabled(index == DolphinView::IconsView); // only the icons view supports categorized sorting + + m_showHiddenFiles->setChecked(m_viewProps->showHiddenFiles()); +} + +#include "viewpropertiesdialog.moc" diff --git a/src/settings/viewpropertiesdialog.h b/src/settings/viewpropertiesdialog.h new file mode 100644 index 000000000..320f8f115 --- /dev/null +++ b/src/settings/viewpropertiesdialog.h @@ -0,0 +1,84 @@ +/*************************************************************************** + * Copyright (C) 2006 by Peter Penz * + * peter.penz@gmx.at * + * * + * 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 of the License, 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. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#ifndef VIEWPROPERTIESDIALOG_H +#define VIEWPROPERTIESDIALOG_H + +#include "libdolphin_export.h" + +#include + +class QCheckBox; +class KComboBox; +class QPushButton; +class QRadioButton; +class ViewProperties; +class DolphinView; + +/** + * @brief Dialog for changing the current view properties of a directory. + * + * It is possible to specify the view mode, the sorting order, whether hidden files + * and previews should be shown. The properties can be assigned to the current folder, + * or recursively to all sub folders. + */ +class LIBDOLPHINPRIVATE_EXPORT ViewPropertiesDialog : public KDialog +{ + Q_OBJECT + +public: + explicit ViewPropertiesDialog(DolphinView* dolphinView); + virtual ~ViewPropertiesDialog(); + +private slots: + void slotOk(); + void slotApply(); + void slotViewModeChanged(int index); + void slotSortingChanged(int index); + void slotSortOrderChanged(int index); + void slotCategorizedSortingChanged(); + void slotShowPreviewChanged(); + void slotShowHiddenFilesChanged(); + void markAsDirty(); + void configureAdditionalInfo(); + +private: + void applyViewProperties(); + void loadSettings(); + +private: + bool m_isDirty; + DolphinView* m_dolphinView; + ViewProperties* m_viewProps; + + KComboBox* m_viewMode; + KComboBox* m_sortOrder; + KComboBox* m_sorting; + QCheckBox* m_showPreview; + QCheckBox* m_showInGroups; + QCheckBox* m_showHiddenFiles; + QPushButton* m_additionalInfo; + QRadioButton* m_applyToCurrentFolder; + QRadioButton* m_applyToSubFolders; + QRadioButton* m_applyToAllFolders; + QCheckBox* m_useAsDefault; +}; + +#endif diff --git a/src/settings/viewpropsprogressinfo.cpp b/src/settings/viewpropsprogressinfo.cpp new file mode 100644 index 000000000..c073d3d46 --- /dev/null +++ b/src/settings/viewpropsprogressinfo.cpp @@ -0,0 +1,148 @@ +/*************************************************************************** + * Copyright (C) 2006 by Peter Penz * + * peter.penz@gmx.at * + * * + * 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 of the License, 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. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#include "viewpropsprogressinfo.h" +#include "applyviewpropsjob.h" +#include "viewproperties.h" + +#include +#include +#include +#include + +#include +#include +#include + +ViewPropsProgressInfo::ViewPropsProgressInfo(QWidget* parent, + const KUrl& dir, + const ViewProperties& viewProps) : + KDialog(parent), + m_dir(dir), + m_viewProps(0), + m_label(0), + m_progressBar(0), + m_dirSizeJob(0), + m_applyViewPropsJob(0), + m_timer(0) +{ + const QSize minSize = minimumSize(); + setMinimumSize(QSize(320, minSize.height())); + + setCaption(i18nc("@title:window", "Applying View Properties")); + setButtons(KDialog::Cancel); + + m_viewProps = new ViewProperties(dir); + m_viewProps->setDirProperties(viewProps); + + // the view properties are stored by the ViewPropsApplierJob, so prevent + // that the view properties are saved twice: + m_viewProps->setAutoSaveEnabled(false); + + QWidget* main = new QWidget(); + QVBoxLayout* topLayout = new QVBoxLayout(); + + m_label = new QLabel(i18nc("@info:progress", "Counting folders: %1", 0), main); + m_progressBar = new QProgressBar(main); + m_progressBar->setMinimum(0); + m_progressBar->setMaximum(0); + m_progressBar->setValue(0); + + topLayout->addWidget(m_label); + topLayout->addWidget(m_progressBar); + + main->setLayout(topLayout); + setMainWidget(main); + + // Use the directory size job to count the number of directories first. This + // allows to give a progress indication for the user when applying the view + // properties later. + m_dirSizeJob = KIO::directorySize(dir); + connect(m_dirSizeJob, SIGNAL(result(KJob*)), + this, SLOT(applyViewProperties())); + + // The directory size job cannot emit any progress signal, as it is not aware + // about the total number of directories. Therefor a timer is triggered, which + // periodically updates the current directory count. + m_timer = new QTimer(this); + connect(m_timer, SIGNAL(timeout()), + this, SLOT(updateProgress())); + m_timer->start(300); + + connect(this, SIGNAL(cancelClicked()), this, SLOT(cancelApplying())); +} + +ViewPropsProgressInfo::~ViewPropsProgressInfo() +{ + delete m_viewProps; + m_viewProps = 0; +} + +void ViewPropsProgressInfo::closeEvent(QCloseEvent* event) +{ + m_timer->stop(); + m_applyViewPropsJob = 0; + KDialog::closeEvent(event); +} + +void ViewPropsProgressInfo::updateProgress() +{ + if (m_dirSizeJob != 0) { + const int subdirs = m_dirSizeJob->totalSubdirs(); + m_label->setText(i18nc("@info:progress", "Counting folders: %1", subdirs)); + } + + if (m_applyViewPropsJob != 0) { + const int progress = m_applyViewPropsJob->progress(); + m_progressBar->setValue(progress); + } +} + +void ViewPropsProgressInfo::applyViewProperties() +{ + if (m_dirSizeJob->error()) { + return; + } + + const int subdirs = m_dirSizeJob->totalSubdirs(); + m_label->setText(i18nc("@info:progress", "Folders: %1", subdirs)); + m_progressBar->setMaximum(subdirs); + + m_dirSizeJob = 0; + + m_applyViewPropsJob = new ApplyViewPropsJob(m_dir, *m_viewProps); + connect(m_applyViewPropsJob, SIGNAL(result(KJob*)), + this, SLOT(close())); +} + +void ViewPropsProgressInfo::cancelApplying() +{ + if (m_dirSizeJob != 0) { + m_dirSizeJob->kill(); + m_dirSizeJob = 0; + } + + if (m_applyViewPropsJob != 0) { + m_applyViewPropsJob->kill(); + m_applyViewPropsJob = 0; + } +} + +#include "viewpropsprogressinfo.moc" diff --git a/src/settings/viewpropsprogressinfo.h b/src/settings/viewpropsprogressinfo.h new file mode 100644 index 000000000..d07d16d67 --- /dev/null +++ b/src/settings/viewpropsprogressinfo.h @@ -0,0 +1,78 @@ +/*************************************************************************** + * Copyright (C) 2006 by Peter Penz * + * peter.penz@gmx.at * + * * + * 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 of the License, 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. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ +#ifndef VIEWPROPSPROGRESSINFO_H +#define VIEWPROPSPROGRESSINFO_H + +#include +#include +#include + +class ApplyViewPropsJob; +class QLabel; +class QProgressBar; +class QTimer; +class ViewProperties; + +/** + * @brief Shows the progress information when applying view properties + * recursively to a given directory. + * + * It is possible to cancel the applying. In this case the already applied + * view properties won't get reverted. + */ +class ViewPropsProgressInfo : public KDialog +{ + Q_OBJECT + +public: + /** + * @param parent Parent widget of the dialog. + * @param dir Directory where the view properties should be applied to + * (including sub directories). + * @param viewProps View properties for the directory \a dir including its + * sub directories. + */ + ViewPropsProgressInfo(QWidget* parent, + const KUrl& dir, + const ViewProperties& viewProps); + + virtual ~ViewPropsProgressInfo(); + +protected: + virtual void closeEvent(QCloseEvent* event); + +private slots: + void updateProgress(); + void applyViewProperties(); + void cancelApplying(); + +private: + KUrl m_dir; + ViewProperties* m_viewProps; + + QLabel* m_label; + QProgressBar* m_progressBar; + + KIO::DirectorySizeJob* m_dirSizeJob; + ApplyViewPropsJob* m_applyViewPropsJob; + QTimer* m_timer; +}; + +#endif diff --git a/src/settings/viewsettingspage.cpp b/src/settings/viewsettingspage.cpp new file mode 100644 index 000000000..44d32af81 --- /dev/null +++ b/src/settings/viewsettingspage.cpp @@ -0,0 +1,98 @@ +/*************************************************************************** + * Copyright (C) 2006 by Peter Penz * + * peter.penz@gmx.at * + * * + * 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 of the License, 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. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#include "viewsettingspage.h" + +#include "settings/columnviewsettingspage.h" +#include "settings/detailsviewsettingspage.h" +#include "dolphinmainwindow.h" +#include "dolphinviewcontainer.h" +#include "settings/generalviewsettingspage.h" +#include "settings/iconsviewsettingspage.h" + +#include +#include +#include + +#include +#include +#include +#include + + +ViewSettingsPage::ViewSettingsPage(DolphinMainWindow* mainWindow, + QWidget* parent) : + SettingsPageBase(parent), + m_pages() +{ + QVBoxLayout* topLayout = new QVBoxLayout(this); + topLayout->setMargin(0); + topLayout->setSpacing(KDialog::spacingHint()); + + KTabWidget* tabWidget = new KTabWidget(this); + + // initialize 'General' tab + const KUrl& url = mainWindow->activeViewContainer()->url(); + GeneralViewSettingsPage* generalPage = new GeneralViewSettingsPage(url, tabWidget); + tabWidget->addTab(generalPage, KIcon("view-choose"), i18nc("@title:tab General settings", "General")); + connect(generalPage, SIGNAL(changed()), this, SIGNAL(changed())); + + // initialize 'Icons' tab + IconsViewSettingsPage* iconsPage = new IconsViewSettingsPage(tabWidget); + tabWidget->addTab(iconsPage, KIcon("view-list-icons"), i18nc("@title:tab", "Icons")); + connect(iconsPage, SIGNAL(changed()), this, SIGNAL(changed())); + + // initialize 'Details' tab + DetailsViewSettingsPage* detailsPage = new DetailsViewSettingsPage(tabWidget); + tabWidget->addTab(detailsPage, KIcon("view-list-details"), i18nc("@title:tab", "Details")); + connect(detailsPage, SIGNAL(changed()), this, SIGNAL(changed())); + + // initialize 'Column' tab + ColumnViewSettingsPage* columnPage = new ColumnViewSettingsPage(tabWidget); + tabWidget->addTab(columnPage, KIcon("view-file-columns"), i18nc("@title:tab", "Column")); + connect(columnPage, SIGNAL(changed()), this, SIGNAL(changed())); + + m_pages.append(generalPage); + m_pages.append(iconsPage); + m_pages.append(detailsPage); + m_pages.append(columnPage); + + topLayout->addWidget(tabWidget, 0, 0); +} + +ViewSettingsPage::~ViewSettingsPage() +{ +} + +void ViewSettingsPage::applySettings() +{ + foreach (ViewSettingsPageBase* page, m_pages) { + page->applySettings(); + } +} + +void ViewSettingsPage::restoreDefaults() +{ + foreach (ViewSettingsPageBase* page, m_pages) { + page->restoreDefaults(); + } +} + +#include "viewsettingspage.moc" diff --git a/src/settings/viewsettingspage.h b/src/settings/viewsettingspage.h new file mode 100644 index 000000000..5e76b30d1 --- /dev/null +++ b/src/settings/viewsettingspage.h @@ -0,0 +1,53 @@ +/*************************************************************************** + * Copyright (C) 2006 by Peter Penz * + * peter.penz@gmx.at * + * * + * 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 of the License, 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. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ +#ifndef VIEWSETTINGSPAGE_H +#define VIEWSETTINGSPAGE_H + +#include +#include + +class ViewSettingsPageBase; +class DolphinMainWindow; + +/** + * @brief Page for the 'View' settings of the Dolphin settings dialog. + * + * The views settings allow to set the properties for the icons mode, + * the details mode and the column mode. + */ +class ViewSettingsPage : public SettingsPageBase +{ + Q_OBJECT + +public: + ViewSettingsPage(DolphinMainWindow* mainWindow, QWidget* parent); + virtual ~ViewSettingsPage(); + + /** @see SettingsPageBase::applySettings() */ + virtual void applySettings(); + + /** @see SettingsPageBase::restoreDefaults() */ + virtual void restoreDefaults(); + +private: + QList m_pages; +}; + +#endif diff --git a/src/settings/viewsettingspagebase.cpp b/src/settings/viewsettingspagebase.cpp new file mode 100644 index 000000000..b610bb0f5 --- /dev/null +++ b/src/settings/viewsettingspagebase.cpp @@ -0,0 +1,31 @@ +/*************************************************************************** + * Copyright (C) 2008 by Peter Penz * + * * + * 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 of the License, 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. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#include "viewsettingspagebase.h" + +ViewSettingsPageBase::ViewSettingsPageBase(QWidget* parent) : + KVBox(parent) +{ +} + +ViewSettingsPageBase::~ViewSettingsPageBase() +{ +} + +#include "viewsettingspagebase.moc" diff --git a/src/settings/viewsettingspagebase.h b/src/settings/viewsettingspagebase.h new file mode 100644 index 000000000..3e85e25cb --- /dev/null +++ b/src/settings/viewsettingspagebase.h @@ -0,0 +1,55 @@ +/*************************************************************************** + * Copyright (C) 2008 by Peter Penz * + * * + * 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 of the License, 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. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#ifndef VIEWSETTINGSPAGEBASE_H +#define VIEWSETTINGSPAGEBASE_H + +#include + +/** + * @brief Base class for view settings configuration pages. + * + * @see GeneralViewSettingsPage; + * @see IconViewSettingsPage + * @see DetailsViewSettingsPage + * @see ColumnViewSettingsPage + */ +class ViewSettingsPageBase : public KVBox +{ + Q_OBJECT + +public: + ViewSettingsPageBase(QWidget* parent); + virtual ~ViewSettingsPageBase(); + + /** + * Applies the settings for the view. + * The settings are persisted automatically when + * closing Dolphin. + */ + virtual void applySettings() = 0; + + /** Restores the settings to default values. */ + virtual void restoreDefaults() = 0; + +signals: + void changed(); +}; + +#endif diff --git a/src/settingspagebase.cpp b/src/settingspagebase.cpp deleted file mode 100644 index 6f8dcbfb6..000000000 --- a/src/settingspagebase.cpp +++ /dev/null @@ -1,31 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2006 by Peter Penz * - * peter.penz@gmx.at * - * * - * 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 of the License, 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. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#include "settingspagebase.h" - -SettingsPageBase::SettingsPageBase(QWidget* parent) : - QWidget(parent) -{} - -SettingsPageBase::~SettingsPageBase() -{} - - -#include "settingspagebase.moc" diff --git a/src/settingspagebase.h b/src/settingspagebase.h deleted file mode 100644 index 19d4cf1f0..000000000 --- a/src/settingspagebase.h +++ /dev/null @@ -1,56 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2006 by Peter Penz * - * peter.penz@gmx.at * - * * - * 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 of the License, 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. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#ifndef SETTINGSPAGEBASE_H -#define SETTINGSPAGEBASE_H - -#include - -/** - * @brief Base class for the settings pages of the Dolphin settings dialog. - * - * @author Peter Penz - */ -class SettingsPageBase : public QWidget -{ - Q_OBJECT - -public: - explicit SettingsPageBase(QWidget* parent); - virtual ~SettingsPageBase(); - - /** - * Must be implemented by a derived class to - * persistently store the settings. - */ - virtual void applySettings() = 0; - - /** - * Must be implemented by a derived class to - * restored the settings to default values. - */ - virtual void restoreDefaults() = 0; - -signals: - /** Is emitted if a setting has been changed. */ - void changed(); -}; - -#endif diff --git a/src/sidebarpage.cpp b/src/sidebarpage.cpp deleted file mode 100644 index 594f59f24..000000000 --- a/src/sidebarpage.cpp +++ /dev/null @@ -1,46 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2006 by Cvetoslav Ludmiloff * - * Copyright (C) 2006 by Peter Penz * - * * - * 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 of the License, 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. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#include "sidebarpage.h" -#include -#include -#include - -SidebarPage::SidebarPage(QWidget* parent) : - QWidget(parent), - m_url(KUrl()) -{ -} - -SidebarPage::~SidebarPage() -{ -} - -const KUrl& SidebarPage::url() const -{ - return m_url; -} - -void SidebarPage::setUrl(const KUrl& url) -{ - m_url = url; -} - -#include "sidebarpage.moc" diff --git a/src/sidebarpage.h b/src/sidebarpage.h deleted file mode 100644 index 20a44758e..000000000 --- a/src/sidebarpage.h +++ /dev/null @@ -1,53 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2006 by Cvetoslav Ludmiloff * - * Copyright (C) 2006 by Peter Penz * - * * - * 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 of the License, 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. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#ifndef _SIDEBARPAGE_H_ -#define _SIDEBARPAGE_H_ - -#include -#include -#include - -/** - * @brief Base widget for all pages that can be embedded into the Sidebar. - */ -class SidebarPage : public QWidget -{ - Q_OBJECT - -public: - explicit SidebarPage(QWidget* parent = 0); - virtual ~SidebarPage(); - - /** Returns the current set URL of the active Dolphin view. */ - const KUrl& url() const; - -public slots: - /** - * This is invoked every time the folder being displayed in the - * active Dolphin view changes. - */ - virtual void setUrl(const KUrl& url); - -private: - KUrl m_url; -}; - -#endif // _SIDEBARPAGE_H_ diff --git a/src/sidebartreeview.cpp b/src/sidebartreeview.cpp deleted file mode 100644 index a876ee6c3..000000000 --- a/src/sidebartreeview.cpp +++ /dev/null @@ -1,147 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2006 by Peter Penz * - * * - * 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 of the License, 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. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#include "sidebartreeview.h" - -#include "dolphincontroller.h" -#include "dolphinmodel.h" -#include "draganddrophelper.h" - -#include -#include -#include -#include -#include - -SidebarTreeView::SidebarTreeView(QWidget* parent) : - KTreeView(parent) -{ - setAcceptDrops(true); - setUniformRowHeights(true); - setSelectionMode(QAbstractItemView::SingleSelection); - setEditTriggers(QAbstractItemView::NoEditTriggers); - setSortingEnabled(true); - setFrameStyle(QFrame::NoFrame); - setDragDropMode(QAbstractItemView::DragDrop); - setDropIndicatorShown(false); - - setVerticalScrollMode(QListView::ScrollPerPixel); - setHorizontalScrollMode(QListView::ScrollPerPixel); - - viewport()->setAttribute(Qt::WA_Hover); - - // make the background transparent and apply the window-text color - // to the text color, so that enough contrast is given for all color - // schemes - QPalette p = palette(); - p.setColor(QPalette::Active, QPalette::Text, p.color(QPalette::Active, QPalette::WindowText)); - p.setColor(QPalette::Inactive, QPalette::Text, p.color(QPalette::Inactive, QPalette::WindowText)); - p.setColor(QPalette::Disabled, QPalette::Text, p.color(QPalette::Disabled, QPalette::WindowText)); - setPalette(p); - viewport()->setAutoFillBackground(false); - - KFileItemDelegate* delegate = new KFileItemDelegate(this); - setItemDelegate(delegate); -} - -SidebarTreeView::~SidebarTreeView() -{ -} - -bool SidebarTreeView::event(QEvent* event) -{ - switch (event->type()) { - case QEvent::Polish: - // hide all columns except of the 'Name' column - hideColumn(DolphinModel::Size); - hideColumn(DolphinModel::ModifiedTime); - hideColumn(DolphinModel::Permissions); - hideColumn(DolphinModel::Owner); - hideColumn(DolphinModel::Group); - hideColumn(DolphinModel::Type); - hideColumn(DolphinModel::Rating); - hideColumn(DolphinModel::Tags); - header()->hide(); - break; - - case QEvent::Show: - // TODO: The opening/closing animation of subtrees flickers in combination with the - // sidebar when using the Oxygen style. As workaround the animation is turned off: - setAnimated(false); - break; - - case QEvent::UpdateRequest: - // a wheel movement will scroll 1 item - if (model()->rowCount() > 0) { - verticalScrollBar()->setSingleStep(sizeHintForRow(0) / 3); - } - break; - - default: - break; - } - - return KTreeView::event(event); -} - -void SidebarTreeView::startDrag(Qt::DropActions supportedActions) -{ - DragAndDropHelper::instance().startDrag(this, supportedActions); -} - -void SidebarTreeView::dragEnterEvent(QDragEnterEvent* event) -{ - KTreeView::dragEnterEvent(event); - if (event->mimeData()->hasUrls()) { - event->acceptProposedAction(); - } -} - -void SidebarTreeView::dragLeaveEvent(QDragLeaveEvent* event) -{ - KTreeView::dragLeaveEvent(event); - setDirtyRegion(m_dropRect); -} - -void SidebarTreeView::dragMoveEvent(QDragMoveEvent* event) -{ - KTreeView::dragMoveEvent(event); - - // TODO: remove this code when the issue #160611 is solved in Qt 4.4 - const QModelIndex index = indexAt(event->pos()); - setDirtyRegion(m_dropRect); - m_dropRect = visualRect(index); - setDirtyRegion(m_dropRect); - - if (event->mimeData()->hasUrls()) { - // accept url drops, independently from the destination item - event->acceptProposedAction(); - } -} - -void SidebarTreeView::dropEvent(QDropEvent* event) -{ - const QModelIndex index = indexAt(event->pos()); - if (index.isValid()) { - emit urlsDropped(index, event); - } - KTreeView::dropEvent(event); -} - -#include "sidebartreeview.moc" diff --git a/src/sidebartreeview.h b/src/sidebartreeview.h deleted file mode 100644 index 93bcbae2e..000000000 --- a/src/sidebartreeview.h +++ /dev/null @@ -1,58 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2006 by Peter Penz * - * * - * 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 of the License, 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. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#ifndef SIDEBARTREEVIEW_H -#define SIDEBARTREEVIEW_H - -#include -#include - -/** - * @brief Tree view widget which is used for the sidebar panel. - * - * @see TreeViewSidebarPage - */ -class SidebarTreeView : public KTreeView -{ - Q_OBJECT - -public: - explicit SidebarTreeView(QWidget* parent = 0); - virtual ~SidebarTreeView(); - -signals: - /** - * Is emitted if the URL have been dropped to - * the index \a index. - */ - void urlsDropped(const QModelIndex& index, QDropEvent* event); - -protected: - virtual bool event(QEvent* event); - virtual void startDrag(Qt::DropActions supportedActions); - virtual void dragEnterEvent(QDragEnterEvent* event); - virtual void dragLeaveEvent(QDragLeaveEvent* event); - virtual void dragMoveEvent(QDragMoveEvent* event); - virtual void dropEvent(QDropEvent* event); - -private: - QRect m_dropRect; -}; - -#endif diff --git a/src/startupsettingspage.cpp b/src/startupsettingspage.cpp deleted file mode 100644 index 35fc47a57..000000000 --- a/src/startupsettingspage.cpp +++ /dev/null @@ -1,169 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Peter Penz * - * * - * 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 of the License, 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. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#include "startupsettingspage.h" - -#include "dolphinsettings.h" -#include "dolphinmainwindow.h" -#include "dolphinview.h" -#include "dolphinviewcontainer.h" - -#include "dolphin_generalsettings.h" - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -StartupSettingsPage::StartupSettingsPage(DolphinMainWindow* mainWin, QWidget* parent) : - SettingsPageBase(parent), - m_mainWindow(mainWin), - m_homeUrl(0), - m_splitView(0), - m_editableUrl(0), - m_showFullPath(0), - m_filterBar(0) -{ - const int spacing = KDialog::spacingHint(); - - QVBoxLayout* topLayout = new QVBoxLayout(this); - KVBox* vBox = new KVBox(this); - vBox->setSpacing(spacing); - - // create 'Home URL' editor - QGroupBox* homeBox = new QGroupBox(i18nc("@title:group", "Home Folder"), vBox); - - KHBox* homeUrlBox = new KHBox(homeBox); - homeUrlBox->setSpacing(spacing); - - new QLabel(i18nc("@label:textbox", "Location:"), homeUrlBox); - m_homeUrl = new KLineEdit(homeUrlBox); - m_homeUrl->setClearButtonShown(true); - - QPushButton* selectHomeUrlButton = new QPushButton(KIcon("folder-open"), QString(), homeUrlBox); - connect(selectHomeUrlButton, SIGNAL(clicked()), - this, SLOT(selectHomeUrl())); - - KHBox* buttonBox = new KHBox(homeBox); - buttonBox->setSpacing(spacing); - - QPushButton* useCurrentButton = new QPushButton(i18nc("@action:button", "Use Current Location"), buttonBox); - connect(useCurrentButton, SIGNAL(clicked()), - this, SLOT(useCurrentLocation())); - QPushButton* useDefaultButton = new QPushButton(i18nc("@action:button", "Use Default Location"), buttonBox); - connect(useDefaultButton, SIGNAL(clicked()), - this, SLOT(useDefaultLocation())); - - QVBoxLayout* homeBoxLayout = new QVBoxLayout(homeBox); - homeBoxLayout->addWidget(homeUrlBox); - homeBoxLayout->addWidget(buttonBox); - - // create 'Split view', 'Editable location' and 'Filter bar' checkboxes - m_splitView = new QCheckBox(i18nc("@option:check Startup Settings", "Split view mode"), vBox); - m_editableUrl = new QCheckBox(i18nc("@option:check Startup Settings", "Editable location bar"), vBox); - m_showFullPath = new QCheckBox(i18nc("@option:check Startup Settings", "Show full path inside location bar"), vBox); - m_filterBar = new QCheckBox(i18nc("@option:check Startup Settings", "Show filter bar"), vBox); - connect(m_splitView, SIGNAL(toggled(bool)), this, SIGNAL(changed())); - connect(m_editableUrl, SIGNAL(toggled(bool)), this, SIGNAL(changed())); - connect(m_showFullPath, SIGNAL(toggled(bool)), this, SIGNAL(changed())); - connect(m_filterBar, SIGNAL(toggled(bool)), this, SIGNAL(changed())); - - // Add a dummy widget with no restriction regarding - // a vertical resizing. This assures that the dialog layout - // is not stretched vertically. - new QWidget(vBox); - - topLayout->addWidget(vBox); - - loadSettings(); - - // it's important connecting 'textChanged' after loadSettings(), as loadSettings() - // invokes m_homeUrl->setText() - connect(m_homeUrl, SIGNAL(textChanged(const QString&)), this, SIGNAL(changed())); -} - -StartupSettingsPage::~StartupSettingsPage() -{ -} - -void StartupSettingsPage::applySettings() -{ - GeneralSettings* settings = DolphinSettings::instance().generalSettings(); - - const KUrl url(m_homeUrl->text()); - KFileItem fileItem(KFileItem::Unknown, KFileItem::Unknown, url); - if (url.isValid() && fileItem.isDir()) { - settings->setHomeUrl(url.prettyUrl()); - } else { - KMessageBox::error(this, i18nc("@info", "The location for the home folder is invalid and will not be applied.")); - } - - settings->setSplitView(m_splitView->isChecked()); - settings->setEditableUrl(m_editableUrl->isChecked()); - settings->setShowFullPath(m_showFullPath->isChecked()); - settings->setFilterBar(m_filterBar->isChecked()); -} - -void StartupSettingsPage::restoreDefaults() -{ - GeneralSettings* settings = DolphinSettings::instance().generalSettings(); - settings->setDefaults(); - loadSettings(); -} - -void StartupSettingsPage::selectHomeUrl() -{ - const QString homeUrl = m_homeUrl->text(); - KUrl url = KFileDialog::getExistingDirectoryUrl(homeUrl, this); - if (!url.isEmpty()) { - m_homeUrl->setText(url.prettyUrl()); - emit changed(); - } -} - -void StartupSettingsPage::useCurrentLocation() -{ - const DolphinView* view = m_mainWindow->activeViewContainer()->view(); - m_homeUrl->setText(view->url().prettyUrl()); -} - -void StartupSettingsPage::useDefaultLocation() -{ - m_homeUrl->setText(QDir::homePath()); -} - -void StartupSettingsPage::loadSettings() -{ - GeneralSettings* settings = DolphinSettings::instance().generalSettings(); - m_homeUrl->setText(settings->homeUrl()); - m_splitView->setChecked(settings->splitView()); - m_editableUrl->setChecked(settings->editableUrl()); - m_showFullPath->setChecked(settings->showFullPath()); - m_filterBar->setChecked(settings->filterBar()); -} - -#include "startupsettingspage.moc" diff --git a/src/startupsettingspage.h b/src/startupsettingspage.h deleted file mode 100644 index a56869cd4..000000000 --- a/src/startupsettingspage.h +++ /dev/null @@ -1,66 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Peter Penz * - * * - * 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 of the License, 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. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ -#ifndef STARTUPSETTINGSPAGE_H -#define STARTUPSETTINGSPAGE_H - -#include - -class DolphinMainWindow; -class KLineEdit; -class QCheckBox; - -/** - * @brief Page for the 'Startup' settings of the Dolphin settings dialog. - * - * The startup settings allow to set the home URL and to configure the - * state of the view mode, split mode and the filter bar when starting Dolphin. - */ -class StartupSettingsPage : public SettingsPageBase -{ - Q_OBJECT - -public: - StartupSettingsPage(DolphinMainWindow* mainWindow, QWidget* parent); - virtual ~StartupSettingsPage(); - - /** @see SettingsPageBase::applySettings() */ - virtual void applySettings(); - - /** @see SettingsPageBase::restoreDefaults() */ - virtual void restoreDefaults(); - -private slots: - void selectHomeUrl(); - void useCurrentLocation(); - void useDefaultLocation(); - -private: - void loadSettings(); - -private: - DolphinMainWindow* m_mainWindow; - KLineEdit* m_homeUrl; - - QCheckBox* m_splitView; - QCheckBox* m_editableUrl; - QCheckBox* m_showFullPath; - QCheckBox* m_filterBar; -}; - -#endif diff --git a/src/tagcloud/newtagdialog.cpp b/src/tagcloud/newtagdialog.cpp deleted file mode 100644 index 8785d578c..000000000 --- a/src/tagcloud/newtagdialog.cpp +++ /dev/null @@ -1,95 +0,0 @@ -/* - Copyright (C) 2008 by Sebastian Trueg - - 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. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include "newtagdialog.h" - -#include - -#include -#include -#include - - -NewTagDialog::NewTagDialog( QWidget* parent ) - : KDialog( parent ) -{ - setCaption( i18nc( "@title:window", "Create New Tag" ) ); - setButtons( Ok|Cancel ); - enableButtonOk( false ); - - setupUi( mainWidget() ); - - connect( m_editTagLabel, SIGNAL( textChanged(const QString&) ), - this, SLOT( slotLabelChanged(const QString&) ) ); - - // TODO: use KGlobal::config() if NewTagDialog will be moved to kdelibs (KDE 4.2?) - KConfigGroup group(KSharedConfig::openConfig("dolphinrc"), "NewTagDialog"); - restoreDialogSize(group); -} - - -NewTagDialog::~NewTagDialog() -{ - // TODO: use KGlobal::config() if NewTagDialog will be moved to kdelibs (KDE 4.2?) - KConfigGroup group(KSharedConfig::openConfig("dolphinrc"), "NewTagDialog"); - saveDialogSize(group, KConfigBase::Persistent); -} - - -QSize NewTagDialog::sizeHint() const -{ - return QSize(400, 256); -} - -void NewTagDialog::slotLabelChanged( const QString& text ) -{ - enableButtonOk( !text.isEmpty() ); -} - - -Nepomuk::Tag NewTagDialog::createTag( QWidget* parent ) -{ - NewTagDialog dlg( parent ); - dlg.m_labelTitle->setText( i18nc( "@title:window", "Create New Tag" ) ); - dlg.m_labelTitle->setComment( i18nc( "@title:window subtitle to previous message", "with optional icon and description" ) ); - dlg.m_labelTitle->setPixmap( KIcon( "nepomuk" ).pixmap( 32, 32 ) ); - - dlg.m_editTagLabel->setFocus(); - - if ( dlg.exec() ) { - QString name = dlg.m_editTagLabel->text(); - QString comment = dlg.m_editTagComment->text(); - QString icon = dlg.m_buttonTagIcon->icon(); - - Nepomuk::Tag newTag( name ); - newTag.setLabel( name ); - newTag.addIdentifier( name ); - if ( !comment.isEmpty() ) { - newTag.setDescription( comment ); - } - if ( !icon.isEmpty() ) { - newTag.addSymbol( icon ); - } - return newTag; - } - else { - return Nepomuk::Tag(); - } -} - -#include "newtagdialog.moc" diff --git a/src/tagcloud/newtagdialog.h b/src/tagcloud/newtagdialog.h deleted file mode 100644 index b11cd1611..000000000 --- a/src/tagcloud/newtagdialog.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - Copyright (C) 2008 by Sebastian Trueg - - 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. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#ifndef _NEW_TAG_DIALOG_H_ -#define _NEW_TAG_DIALOG_H_ - -#include -#include "ui_newtagdialog.h" - -namespace Nepomuk { - class Tag; -} - -class NewTagDialog : public KDialog, public Ui_NewTagDialog -{ - Q_OBJECT - -public: - ~NewTagDialog(); - - virtual QSize sizeHint() const; - - static Nepomuk::Tag createTag( QWidget* parent = 0 ); - -private Q_SLOTS: - void slotLabelChanged( const QString& text ); - -private: - NewTagDialog( QWidget* parent = 0 ); -}; - -#endif diff --git a/src/tagcloud/newtagdialog.ui b/src/tagcloud/newtagdialog.ui deleted file mode 100644 index d9bd666b5..000000000 --- a/src/tagcloud/newtagdialog.ui +++ /dev/null @@ -1,110 +0,0 @@ - - NewTagDialog - - - - 0 - 0 - 390 - 149 - - - - - - - - - - - - - - Qt::Vertical - - - QSizePolicy::Fixed - - - - 20 - 5 - - - - - - - - Name: - - - - - - - - - - - - - 0 - 0 - - - - - - - - - - - - - Qt::Vertical - - - QSizePolicy::Fixed - - - - 20 - 10 - - - - - - - - Detailed description (optional): - - - - - - - - - - - KIconButton - QPushButton -

kicondialog.h
- - - KLineEdit - QLineEdit -
klineedit.h
-
- - KTitleWidget - QWidget -
ktitlewidget.h
-
- - - - diff --git a/src/tagcloud/resourcetaggingwidget.cpp b/src/tagcloud/resourcetaggingwidget.cpp deleted file mode 100644 index 1e3fffe8f..000000000 --- a/src/tagcloud/resourcetaggingwidget.cpp +++ /dev/null @@ -1,193 +0,0 @@ -/* - This file is part of the Nepomuk KDE project. - Copyright (C) 2007 Sebastian Trueg - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License version 2 as published by the Free Software Foundation. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - */ - -#include "resourcetaggingwidget.h" -#include "tagcloud.h" -#include "taggingpopup.h" -#include "../nepomukmassupdatejob.h" - -#include -#include -#include -#include -#include - -#include - -namespace Nepomuk { - inline uint qHash( const Tag& res ) - { - return qHash( res.resourceUri().toString() ); - } -} - - -class Nepomuk::ResourceTaggingWidget::Private -{ -public: - QList resources; - - TagCloud* resourceTagCloud; - TaggingPopup* popup; - - QList resourceTags; - - void showTaggingPopup( const QPoint& ); - void _k_slotShowTaggingPopup(); - void _k_metadataUpdateDone(); - static QList intersectTags( const QList& ); - - ResourceTaggingWidget* q; -}; - - -void Nepomuk::ResourceTaggingWidget::Private::showTaggingPopup( const QPoint& pos ) -{ - popup->showAllTags(); - resourceTags = intersectTags( resources ); - Q_FOREACH( const Tag &tag, resourceTags ) { - popup->setTagSelected( tag, true ); - } - - popup->exec( pos ); - - MassUpdateJob* job = MassUpdateJob::tagResources( resources, resourceTags ); - connect( job, SIGNAL( result( KJob* ) ), - q, SLOT( _k_metadataUpdateDone() ) ); - q->setEnabled( false ); // no updates during execution - job->start(); - - resourceTagCloud->showTags( resourceTags ); -} - - -void Nepomuk::ResourceTaggingWidget::Private::_k_slotShowTaggingPopup() -{ - showTaggingPopup( QCursor::pos() ); -} - - -void Nepomuk::ResourceTaggingWidget::Private::_k_metadataUpdateDone() -{ - q->setEnabled( true ); -} - - -QList Nepomuk::ResourceTaggingWidget::Private::intersectTags( const QList& res ) -{ - if ( res.count() == 1 ) { - return res.first().tags(); - } - else if ( !res.isEmpty() ) { - // determine the tags used for all resources - QSet tags = QSet::fromList( res.first().tags() ); - QList::const_iterator it = res.begin(); - for ( ++it; it != res.end(); ++it ) { - tags.intersect( QSet::fromList( (*it).tags() ) ); - } - return tags.values(); - } - else { - return QList(); - } -} - - -Nepomuk::ResourceTaggingWidget::ResourceTaggingWidget( QWidget* parent ) - : QWidget( parent ), - d( new Private() ) -{ - d->q = this; - - QVBoxLayout* layout = new QVBoxLayout( this ); - layout->setMargin( 0 ); - d->resourceTagCloud = new TagCloud( this ); - layout->addWidget( d->resourceTagCloud ); - QLabel* changeTagsLabel = new QLabel( "

" + i18nc( "@label", "Change Tags..." ) + "", this ); - connect( changeTagsLabel, SIGNAL( linkActivated( const QString ) ), - this, SLOT( _k_slotShowTaggingPopup() ) ); - layout->addWidget( changeTagsLabel ); - - // the popup tag cloud - d->popup = new TaggingPopup; - d->popup->setSelectionEnabled( true ); - d->popup->setNewTagButtonEnabled( true ); - - connect( d->popup, SIGNAL( tagToggled( const Nepomuk::Tag&, bool ) ), - this, SLOT( slotTagToggled( const Nepomuk::Tag&, bool ) ) ); - connect( d->popup, SIGNAL( tagAdded( const Nepomuk::Tag& ) ), - this, SLOT( slotTagAdded( const Nepomuk::Tag& ) ) ); - - connect( d->resourceTagCloud, SIGNAL( tagClicked( const Nepomuk::Tag& ) ), - this, SIGNAL( tagClicked( const Nepomuk::Tag& ) ) ); -} - - -Nepomuk::ResourceTaggingWidget::~ResourceTaggingWidget() -{ - delete d->popup; - delete d; -} - - -void Nepomuk::ResourceTaggingWidget::setResource( const Nepomuk::Resource& res ) -{ - setResources( QList() << res ); -} - - -void Nepomuk::ResourceTaggingWidget::setResources( const QList& resList ) -{ - d->resources = resList; - d->resourceTagCloud->showTags( d->intersectTags( resList ) ); -} - - -void Nepomuk::ResourceTaggingWidget::slotTagToggled( const Nepomuk::Tag& tag, bool enabled ) -{ - if ( enabled ) { - d->resourceTags.append( tag ); - } - else { - d->resourceTags.removeAll( tag ); - } - d->popup->hide(); -} - - -void Nepomuk::ResourceTaggingWidget::slotTagAdded( const Nepomuk::Tag& tag ) -{ - // assign it right away - d->resourceTags.append( tag ); -// d->resource.addTag( tag ); -} - - -void Nepomuk::ResourceTaggingWidget::contextMenuEvent( QContextMenuEvent* e ) -{ - d->showTaggingPopup( e->globalPos() ); -} - - -void Nepomuk::ResourceTaggingWidget::showTagPopup( const QPoint& pos ) -{ - d->showTaggingPopup( pos ); -} - -#include "resourcetaggingwidget.moc" diff --git a/src/tagcloud/resourcetaggingwidget.h b/src/tagcloud/resourcetaggingwidget.h deleted file mode 100644 index 4ddcea881..000000000 --- a/src/tagcloud/resourcetaggingwidget.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - This file is part of the Nepomuk KDE project. - Copyright (C) 2007 Sebastian Trueg - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License version 2 as published by the Free Software Foundation. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - */ - -#ifndef _NEPOMUK_RESOURCE_TAGGING_WIDGET_H_ -#define _NEPOMUK_RESOURCE_TAGGING_WIDGET_H_ - -#include - -#include - -class QEvent; -class QContextMenuEvent; - -namespace Nepomuk { - class ResourceTaggingWidget : public QWidget - { - Q_OBJECT - - public: - ResourceTaggingWidget( QWidget* parent = 0 ); - ~ResourceTaggingWidget(); - - Q_SIGNALS: - void tagClicked( const Nepomuk::Tag& tag ); - - public Q_SLOTS: - void setResource( const Nepomuk::Resource& ); - void setResources( const QList& ); - void showTagPopup( const QPoint& pos ); - - private Q_SLOTS: - void slotTagToggled( const Nepomuk::Tag& tag, bool enabled ); - void slotTagAdded( const Nepomuk::Tag& tag ); - - protected: - void contextMenuEvent( QContextMenuEvent* e ); - - private: - class Private; - Private* const d; - - Q_PRIVATE_SLOT( d, void _k_slotShowTaggingPopup() ) - Q_PRIVATE_SLOT( d, void _k_metadataUpdateDone() ) - }; -} - -#endif diff --git a/src/tagcloud/tagcloud.cpp b/src/tagcloud/tagcloud.cpp deleted file mode 100644 index 0074d1796..000000000 --- a/src/tagcloud/tagcloud.cpp +++ /dev/null @@ -1,1005 +0,0 @@ -/* - This file is part of the Nepomuk KDE project. - Copyright (C) 2007 Sebastian Trueg - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License version 2 as published by the Free Software Foundation. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - */ - -#include "tagcloud.h" -#include "newtagdialog.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include -#include -#include -#include - -#include - -#include - - -namespace { - const int s_hSpacing = 10; - const int s_vSpacing = 5; - - class TagNode { - public: - TagNode() - : weight( 0 ), - selected( false ) { - } - - // fixed info - Nepomuk::Tag tag; - int weight; - - // misc - bool selected; - - // info generated by rebuildCloud - QFont font; - QRect rect; - QRect zoomedRect; - QString text; - }; - - bool tagNodeNameLessThan( const TagNode& n1, const TagNode& n2 ) { - return n1.text < n2.text; - } - - bool tagNodeWeightLessThan( const TagNode& n1, const TagNode& n2 ) { - return n1.weight < n2.weight; - } - - int rowLength( const QList& row ) { - int rowLen = 0; - for ( int j = 0; j < row.count(); ++j ) { - rowLen += row[j]->rect.width(); - if ( j < row.count()-1 ) { - rowLen += s_hSpacing; - } - } - return rowLen; - } - - int rowHeight( const QList& row ) { - int h = 0; - for ( int j = 0; j < row.count(); ++j ) { - h = qMax( row[j]->rect.height(), h ); - } - return h; - } - - QSize cloudSize( const QList >& rows ) { - int w = 0; - int h = 0; - for ( int i = 0; i < rows.count(); ++i ) { - w = qMax( w, rowLength( rows[i] ) ); - h += rowHeight( rows[i] ); - if ( i < rows.count()-1 ) { - h += s_vSpacing; - } - } - return QSize( w, h ); - } -} - - -class Nepomuk::TagCloud::Private -{ -public: - Private( TagCloud* parent ) - : maxFontSize( 0 ), - minFontSize( 0 ), - maxNumberDisplayedTags( 0 ), - selectionEnabled( false ), - newTagButtonEnabled( false ), - alignment( Qt::AlignCenter ), - sorting( SortAlpabetically ), - zoomEnabled( true ), - showAllTags( false ), - customNewTagAction( 0 ), - hoverTag( 0 ), - cachedHfwWidth( -1 ), - m_parent( parent ) { - newTagNode.text = i18nc( "@label", "New Tag..." ); - } - - int maxFontSize; - int minFontSize; - int maxNumberDisplayedTags; - bool selectionEnabled; - bool newTagButtonEnabled; - Qt::Alignment alignment; - Sorting sorting; - bool zoomEnabled; - - // The resource whose tags we are showing - // invalid if we show all tags or a selection - KUrl resource; - bool showAllTags; - - // the actual nodes - QList nodes; - - // just a helper structure for speeding up things - QList > rows; - - TagNode newTagNode; - QAction* customNewTagAction; - - TagNode* hoverTag; - - QMatrix zoomMatrix; - - QSize cachedSizeHint; - int cachedHfwWidth; - int cachedHfwHeight; - - void invalidateCachedValues() { - cachedSizeHint = QSize(); - cachedHfwWidth = -1; - } - - int getMinFontSize() const; - int getMaxFontSize() const; - void updateNodeWeights(); - void updateNodeFonts(); - void sortNodes(); - void rebuildCloud(); - TagNode* tagAt( const QPoint& pos ); - TagNode* findTagInRow( const QList& row, const QPoint& pos ); - TagNode* nodeForTag( const Tag& tag ); - int calculateWeight( const Nepomuk::Tag& tag ); - -private: - TagCloud* m_parent; -}; - - -int Nepomuk::TagCloud::Private::getMinFontSize() const -{ - return minFontSize > 0 ? minFontSize : ( 8 * m_parent->font().pointSize() / 10 ); -} - - -int Nepomuk::TagCloud::Private::getMaxFontSize() const -{ - return maxFontSize > 0 ? maxFontSize : ( 22 * m_parent->font().pointSize() / 10 ); -} - - -int Nepomuk::TagCloud::Private::calculateWeight( const Nepomuk::Tag& tag ) -{ - // stupid SPARQL has no functions such as count! - Soprano::QueryResultIterator it - = ResourceManager::instance()->mainModel()->executeQuery( QString( "select ?r where { ?r <%1> <%2> . }" ) - .arg( Soprano::Vocabulary::NAO::hasTag().toString() ) - .arg( QString::fromAscii( tag.resourceUri().toEncoded() ) ), - Soprano::Query::QueryLanguageSparql ); - int w = 0; - while ( it.next() ) { - ++w; - } - return w; -} - - -void Nepomuk::TagCloud::Private::updateNodeWeights() -{ - bool changedWeights = false; - for ( QList::iterator it = nodes.begin(); - it != nodes.end(); ++it ) { - TagNode& node = *it; - int w = calculateWeight( node.tag ); - if ( w != node.weight ) { - node.weight = w; - changedWeights = true; - } - } - if ( changedWeights ) { - updateNodeFonts(); - } -} - - -void Nepomuk::TagCloud::Private::updateNodeFonts() -{ - int maxWeight = 0; - int minWeight = 0; - for ( QList::iterator it = nodes.begin(); - it != nodes.end(); ++it ) { - TagNode& node = *it; - minWeight = qMin( minWeight, node.weight ); - maxWeight = qMax( maxWeight, node.weight ); - } - - // calculate font sizes - // ---------------------------------------------- - int usedMinFontSize = getMinFontSize(); - int usedMaxFontSize = getMaxFontSize(); - for ( QList::iterator it = nodes.begin(); - it != nodes.end(); ++it ) { - TagNode& node = *it; - double normalizedWeight = (double)(node.weight - minWeight) / (double)qMax(maxWeight - minWeight, 1); - node.font = m_parent->font(); - node.font.setPointSize( usedMinFontSize + (int)((double)(usedMaxFontSize-usedMinFontSize) * normalizedWeight) ); - if( normalizedWeight > 0.8 ) - node.font.setBold( true ); - } - - if ( newTagButtonEnabled ) { - newTagNode.font = m_parent->font(); - newTagNode.font.setPointSize( usedMinFontSize ); - newTagNode.font.setUnderline( true ); - } -} - - -void Nepomuk::TagCloud::Private::sortNodes() -{ - if ( sorting == SortAlpabetically ) { - qSort( nodes.begin(), nodes.end(), tagNodeNameLessThan ); - } - else if ( sorting == SortByWeight ) { - qSort( nodes.begin(), nodes.end(), tagNodeWeightLessThan ); - } - else if ( sorting == SortRandom ) { - KRandomSequence().randomize( nodes ); - } -} - - -void Nepomuk::TagCloud::Private::rebuildCloud() -{ - // - Always try to be quadratic - // - Always prefer to expand horizontally - // - If we cannot fit everything into m_parent->contentsRect(), zoom - // - If alignment & Qt::AlignJustify insert spaces between tags - - sortNodes(); - - QRect contentsRect = m_parent->contentsRect(); - - // initialize the nodes' sizes - // ---------------------------------------------- - for ( QList::iterator it = nodes.begin(); - it != nodes.end(); ++it ) { - TagNode& node = *it; - node.rect = QFontMetrics( node.font ).boundingRect( node.text ); - } - if ( newTagButtonEnabled ) { - newTagNode.rect = QFontMetrics( newTagNode.font ).boundingRect( customNewTagAction ? customNewTagAction->text() : newTagNode.text ); - } - - - // and position the nodes - // ---------------------------------------------- - rows.clear(); - if ( !nodes.isEmpty() || newTagButtonEnabled ) { - if ( 0 ) { // FIXME: make it configurable - QRect lineRect; - QRect totalRect; - QList row; - for ( QList::iterator it = nodes.begin(); - it != nodes.end(); /* We do increment it below */ ) { - TagNode& node = *it; - - int usedSpacing = row.isEmpty() ? 0 : s_hSpacing; - if ( lineRect.width() + usedSpacing + node.rect.width() <= contentsRect.width() ) { - node.rect.moveBottomLeft( QPoint( lineRect.right() + usedSpacing, lineRect.bottom() ) ); - QRect newLineRect = lineRect.united( node.rect ); - newLineRect.moveTopLeft( lineRect.topLeft() ); - lineRect = newLineRect; - row.append( &node ); - - // update all other nodes in this line - Q_FOREACH( TagNode* n, row ) { - n->rect.moveBottom( lineRect.bottom() - ( lineRect.height() - n->rect.height() )/2 ); - } - - ++it; - } - else { - rows.append( row ); - row.clear(); - int newLineTop = lineRect.bottom() + s_vSpacing; - lineRect = QRect(); - lineRect.moveTop( newLineTop ); - } - } - rows.append( row ); - } - else { - // initialize first row - rows.append( QList() ); - for ( QList::iterator it = nodes.begin(); - it != nodes.end(); ++it ) { - TagNode& node = *it; - rows.first().append( &node ); - } - if ( newTagButtonEnabled ) { - rows.first().append( &newTagNode ); - } - - // calculate the rows - QList > bestRows( rows ); - QSize size( rowLength( rows.first() ), rowHeight( rows.first() ) ); - QSize bestSize( size ); - while ( ( size.height() < size.width() || - size.width() > contentsRect.width() ) && - size.height() <= contentsRect.height() ) { - // find the longest row - int maxRow = 0; - int maxLen = 0; - for ( int i = 0; i < rows.count(); ++i ) { - int rowLen = rowLength( rows[i] ); - if ( rowLen > maxLen ) { - maxLen = rowLen; - maxRow = i; - } - } - - // move the last item from the longest row to the next row - TagNode* node = rows[maxRow].takeLast(); - if ( rows.count() <= maxRow+1 ) { - rows.append( QList() ); - } - rows[maxRow+1].prepend( node ); - - // update the size - size = cloudSize( rows ); - - if ( size.width() < bestSize.width() && - ( size.width() > size.height() || - bestSize.width() > contentsRect.width() ) && - size.height() <= contentsRect.height() ) { - bestSize = size; - bestRows = rows; - } - } - rows = bestRows; - - // position the tags - int y = 0; - for ( QList >::iterator rowIt = rows.begin(); rowIt != rows.end(); ++rowIt ) { - QList& row = *rowIt; - int h = rowHeight( row ); - int x = 0; - Q_FOREACH( TagNode* node, row ) { - node->rect.moveTop( y + ( h - node->rect.height() )/2 ); - node->rect.moveLeft( x ); - x += s_hSpacing + node->rect.width(); - } - y += h + s_vSpacing; - } - } - - - // let's see if we have to zoom - // ---------------------------------------------- - zoomMatrix = QMatrix(); - int w = contentsRect.width(); - if ( zoomEnabled ) { - for ( QList >::iterator rowIt = rows.begin(); rowIt != rows.end(); ++rowIt ) { - QList& row = *rowIt; - w = qMax( w, row.last()->rect.right() ); - } - if ( w > contentsRect.width() ) { - double zoomFactor = ( double )contentsRect.width() / ( double )w; - zoomMatrix.scale( zoomFactor, zoomFactor ); - } - } - - // force horizontal alignment - // ---------------------------------------------- - for ( QList >::iterator rowIt = rows.begin(); rowIt != rows.end(); ++rowIt ) { - QList& row = *rowIt; - int space = /*contentsRect.right()*/w - row.last()->rect.right(); - if ( alignment & ( Qt::AlignRight|Qt::AlignHCenter ) ) { - Q_FOREACH( TagNode* node, row ) { - node->rect.moveLeft( node->rect.left() + ( alignment & Qt::AlignRight ? space : space/2 ) ); - } - } - else if ( alignment & Qt::AlignJustify && row.count() > 1 ) { - space /= ( row.count()-1 ); - int i = 0; - Q_FOREACH( TagNode* node, row ) { - node->rect.moveLeft( node->rect.left() + ( space * i++ ) ); - } - } - } - - // force vertical alignment - // ---------------------------------------------- - int verticalSpace = contentsRect.bottom() - rows.last().first()->rect.bottom(); - if ( alignment & ( Qt::AlignBottom|Qt::AlignVCenter ) ) { - for ( QList >::iterator rowIt = rows.begin(); rowIt != rows.end(); ++rowIt ) { - Q_FOREACH( TagNode* node, *rowIt ) { - node->rect.moveTop( node->rect.top() + ( alignment & Qt::AlignBottom ? verticalSpace : verticalSpace/2 ) ); - } - } - } - - for( QList::iterator it = nodes.begin(); it != nodes.end(); ++it ) { - it->zoomedRect = zoomMatrix.mapRect( it->rect ); - } - newTagNode.zoomedRect = zoomMatrix.mapRect( newTagNode.rect ); - } - - m_parent->updateGeometry(); - m_parent->update(); -} - - -// binary search in row -TagNode* Nepomuk::TagCloud::Private::findTagInRow( const QList& row, const QPoint& pos ) -{ - int x = m_parent->width() ? row.count() * pos.x() / m_parent->width() : 0; - - int i = 0; - while ( 1 ) { - if ( x-i >= 0 && x-i < row.count() && row[x-i]->zoomedRect.contains( pos ) ) { - return row[x-i]; - } - else if ( x+i >= 0 && x+i < row.count() && row[x+i]->zoomedRect.contains( pos ) ) { - return row[x+i]; - } - if ( x-i < 0 && x+i >= row.count() ) { - return 0; - } - ++i; - } - return 0; -} - - -// binary search in cloud -TagNode* Nepomuk::TagCloud::Private::tagAt( const QPoint& pos ) -{ - int y = m_parent->height() ? rows.count() * pos.y() / m_parent->height() : 0; - - int i = 0; - while ( 1 ) { - if ( y-i >= 0 && y-i < rows.count() ) { - if ( TagNode* node = findTagInRow( rows[y-i], pos ) ) { - return node; - } - } - if ( y+i >= 0 && y+i < rows.count() ) { - if ( TagNode* node = findTagInRow( rows[y+i], pos ) ) { - return node; - } - } - if ( y-i < 0 && y+i >= rows.count() ) { - return 0; - } - ++i; - } - return 0; -} - - -TagNode* Nepomuk::TagCloud::Private::nodeForTag( const Tag& tag ) -{ - for ( QList::iterator it = nodes.begin(); - it != nodes.end(); ++it ) { - TagNode& node = *it; - if ( tag == node.tag ) { - return &node; - } - } - return 0; -} - - - -Nepomuk::TagCloud::TagCloud( QWidget* parent ) - : QFrame( parent ), - d( new Private(this) ) -{ - QSizePolicy policy( QSizePolicy::Preferred, - QSizePolicy::Preferred ); - policy.setHeightForWidth( true ); - setSizePolicy( policy ); - setMouseTracking( true ); - - // Since signals are delivered in no particular order - // our slot might be called before the resources are updated - // Then, we would use invalid cached data. - // By using queued connections this problem should be solved. - connect( ResourceManager::instance()->mainModel(), - SIGNAL( statementAdded( const Soprano::Statement& ) ), - this, - SLOT( slotStatementAdded( const Soprano::Statement& ) ), - Qt::QueuedConnection ); - connect( ResourceManager::instance()->mainModel(), - SIGNAL( statementRemoved( const Soprano::Statement& ) ), - this, - SLOT( slotStatementRemoved( const Soprano::Statement& ) ), - Qt::QueuedConnection ); -} - - -Nepomuk::TagCloud::~TagCloud() -{ - delete d; -} - - -void Nepomuk::TagCloud::setMaxFontSize( int size ) -{ - d->invalidateCachedValues(); - d->maxFontSize = size; - d->updateNodeFonts(); - d->rebuildCloud(); -} - - -void Nepomuk::TagCloud::setMinFontSize( int size ) -{ - d->invalidateCachedValues(); - d->minFontSize = size; - d->updateNodeFonts(); - d->rebuildCloud(); -} - - -void Nepomuk::TagCloud::setMaxNumberDisplayedTags( int n ) -{ - d->maxNumberDisplayedTags = n; - d->rebuildCloud(); -} - - -void Nepomuk::TagCloud::setSelectionEnabled( bool enabled ) -{ - d->selectionEnabled = enabled; - update(); -} - - -void Nepomuk::TagCloud::setNewTagButtonEnabled( bool enabled ) -{ - d->newTagButtonEnabled = enabled; - d->rebuildCloud(); -} - - -bool Nepomuk::TagCloud::zoomEnabled() const -{ - return d->zoomEnabled; -} - - -void Nepomuk::TagCloud::setZoomEnabled( bool zoom ) -{ - if ( d->zoomEnabled != zoom ) { - d->zoomEnabled = zoom; - d->rebuildCloud(); - } -} - - -void Nepomuk::TagCloud::setContextMenuEnabled( bool enabled ) -{ - Q_UNUSED(enabled); -} - - -void Nepomuk::TagCloud::setAlignment( Qt::Alignment alignment ) -{ - d->alignment = alignment; - d->rebuildCloud(); -} - - -void Nepomuk::TagCloud::setSorting( Sorting s ) -{ - d->invalidateCachedValues(); - d->sorting = s; - d->rebuildCloud(); -} - - -void Nepomuk::TagCloud::showAllTags() -{ - showTags( Nepomuk::Tag::allTags() ); - d->showAllTags = true; -} - - -void Nepomuk::TagCloud::showResourceTags( const Resource& resource ) -{ - showTags( resource.tags() ); - d->resource = resource.uri(); -} - - -void Nepomuk::TagCloud::showTags( const QList& tags ) -{ - d->resource = QUrl(); - d->showAllTags = false; - d->invalidateCachedValues(); - d->nodes.clear(); - Q_FOREACH( const Tag &tag, tags ) { - TagNode node; - node.tag = tag; - node.weight = d->calculateWeight( tag ); - node.text = node.tag.genericLabel(); - - d->nodes.append( node ); - } - d->updateNodeFonts(); - d->rebuildCloud(); -} - - -void Nepomuk::TagCloud::setTagSelected( const Tag& tag, bool selected ) -{ - if ( TagNode* node = d->nodeForTag( tag ) ) { - node->selected = selected; - if ( d->selectionEnabled ) { - update( node->zoomedRect ); - } - } -} - - -QSize Nepomuk::TagCloud::sizeHint() const -{ - // If we have tags d->rebuildCloud() has been called at least once, - // thus, we have proper rects (i.e. needed sizes) - - if ( !d->cachedSizeHint.isValid() ) { - QList > rows; - rows.append( QList() ); - for ( QList::iterator it = d->nodes.begin(); - it != d->nodes.end(); ++it ) { - TagNode& node = *it; - rows.first().append( &node ); - } - if ( d->newTagButtonEnabled ) { - rows.first().append( &d->newTagNode ); - } - - QSize size( rowLength( rows.first() ), rowHeight( rows.first() ) ); - QSize bestSize( size ); - while ( size.height() < size.width() ) { - // find the longest row - int maxRow = 0; - int maxLen = 0; - for ( int i = 0; i < rows.count(); ++i ) { - int rowLen = rowLength( rows[i] ); - if ( rowLen > maxLen ) { - maxLen = rowLen; - maxRow = i; - } - } - - // move the last item from the longest row to the next row - TagNode* node = rows[maxRow].takeLast(); - if ( rows.count() <= maxRow+1 ) { - rows.append( QList() ); - } - rows[maxRow+1].prepend( node ); - - // update the size - size = cloudSize( rows ); - - if ( size.width() < bestSize.width() && - size.width() > size.height() ) { - bestSize = size; - } - } - - d->cachedSizeHint = QSize( bestSize.width() + frameWidth()*2, - bestSize.height() + frameWidth()*2 ); - } - - return d->cachedSizeHint; -} - - -QSize Nepomuk::TagCloud::minimumSizeHint() const -{ - return QFrame::minimumSizeHint(); - // If we have tags d->rebuildCloud() has been called at least once, - // thus, we have proper rects (i.e. needed sizes) - if ( d->nodes.isEmpty() && !d->newTagButtonEnabled ) { - return QSize( fontMetrics().width( i18nc( "@label Indicator when no tags defined", "No Tags" ) ), fontMetrics().height() ); - } - else { - QSize size; - for ( QList::iterator it = d->nodes.begin(); - it != d->nodes.end(); ++it ) { - size.setWidth( qMax( size.width(), ( *it ).rect.width() ) ); - size.setHeight( qMax( size.height(), ( *it ).rect.height() ) ); - } - if ( d->newTagButtonEnabled ) { - size.setWidth( qMax( size.width(), d->newTagNode.rect.width() ) ); - size.setHeight( qMax( size.height(), d->newTagNode.rect.height() ) ); - } - size.setWidth( size.width() + frameWidth()*2 ); - size.setHeight( size.height() + frameWidth()*2 ); - return size; - } -} - - -int Nepomuk::TagCloud::heightForWidth( int contentsWidth ) const -{ - // If we have tags d->rebuildCloud() has been called at least once, - // thus, we have proper rects (i.e. needed sizes) - - if ( d->cachedHfwWidth != contentsWidth ) { - // have to keep in mind the frame - contentsWidth -= frameWidth()*2; - - QList allNodes; - for ( QList::iterator it = d->nodes.begin(); - it != d->nodes.end(); ++it ) { - TagNode& node = *it; - allNodes.append( &node ); - } - if ( d->newTagButtonEnabled ) { - allNodes.append( &d->newTagNode ); - } - - int h = 0; - bool newRow = true; - int rowW = 0; - int rowH = 0; - int maxW = 0; - for ( int i = 0; i < allNodes.count(); ++i ) { - int w = rowW; - if ( !newRow ) { - w += s_hSpacing; - } - newRow = false; - w += allNodes[i]->rect.width(); - if ( w <= contentsWidth ) { - rowH = qMax( rowH, allNodes[i]->rect.height() ); - rowW = w; - } - else { - if ( h > 0 ) { - h += s_vSpacing; - } - h += rowH; - rowH = allNodes[i]->rect.height(); - rowW = allNodes[i]->rect.width(); - } - maxW = qMax( maxW, rowW ); - } - if ( rowH > 0 ) { - h += s_vSpacing + rowH; - } - - d->cachedHfwWidth = contentsWidth; - d->cachedHfwHeight = h; - - // zooming - if ( maxW > contentsWidth ) { - d->cachedHfwHeight = d->cachedHfwHeight * contentsWidth / maxW; - } - } - - return d->cachedHfwHeight + frameWidth()*2; -} - - -void Nepomuk::TagCloud::resizeEvent( QResizeEvent* e ) -{ - QFrame::resizeEvent( e ); - d->rebuildCloud(); - update(); -} - - -void Nepomuk::TagCloud::paintEvent( QPaintEvent* e ) -{ - QFrame::paintEvent( e ); - - KStatefulBrush normalTextBrush( KColorScheme::View, KColorScheme::NormalText ); - KStatefulBrush activeTextBrush( KColorScheme::View, KColorScheme::VisitedText ); - KStatefulBrush hoverTextBrush( KColorScheme::View, KColorScheme::ActiveText ); - - QPainter p( this ); - QRegion paintRegion = e->region(); - - p.save(); - p.setMatrix( d->zoomMatrix ); - - for ( QList::iterator it = d->nodes.begin(); - it != d->nodes.end(); ++it ) { - TagNode& node = *it; - - if ( paintRegion.contains( node.zoomedRect ) ) { - p.setFont( node.font ); - - if ( &node == d->hoverTag ) { - p.setPen( hoverTextBrush.brush( this ).color() ); - } - else if ( d->selectionEnabled && node.selected ) { - p.setPen( activeTextBrush.brush( this ).color() ); - } - else { - p.setPen( normalTextBrush.brush( this ).color() ); - } - p.drawText( node.rect, Qt::AlignCenter, node.text ); - } - } - - if ( d->newTagButtonEnabled ) { - p.setFont( d->newTagNode.font ); - if ( &d->newTagNode == d->hoverTag ) { - p.setPen( hoverTextBrush.brush( this ).color() ); - } - else { - p.setPen( normalTextBrush.brush( this ).color() ); - } - p.drawText( d->newTagNode.rect, Qt::AlignCenter, d->customNewTagAction ? d->customNewTagAction->text() : d->newTagNode.text ); - } - - p.restore(); -} - - -void Nepomuk::TagCloud::mousePressEvent( QMouseEvent* e ) -{ - if ( e->button() == Qt::LeftButton ) { - if ( TagNode* node = d->tagAt( e->pos() ) ) { - kDebug() << "clicked" << node->text; - if ( node == &d->newTagNode ) { - if ( d->customNewTagAction ) { - d->customNewTagAction->trigger(); - } - else { - // FIXME: nicer gui - Tag newTag = NewTagDialog::createTag( this ); - if ( newTag.isValid() ) { - emit tagAdded( newTag ); - } - } - } - else { - emit tagClicked( node->tag ); - if ( d->selectionEnabled ) { - kDebug() << "Toggleing tag" << node->text; - node->selected = !node->selected; - emit tagToggled( node->tag, node->selected ); - update( node->zoomedRect ); - } - } - } - } -} - - -void Nepomuk::TagCloud::mouseMoveEvent( QMouseEvent* e ) -{ - if ( e->buttons() == Qt::NoButton ) { - - TagNode* oldHoverTag = d->hoverTag; - - if ( ( d->hoverTag = d->tagAt( e->pos() ) ) && - !d->selectionEnabled ) { - setCursor( Qt::PointingHandCursor ); - } - else if ( d->newTagButtonEnabled && - d->newTagNode.zoomedRect.contains( e->pos() ) ) { - d->hoverTag = &d->newTagNode; - setCursor( Qt::PointingHandCursor ); - } - else { - unsetCursor(); - } - - if ( oldHoverTag || d->hoverTag ) { - QRect updateRect; - if ( d->hoverTag ) - updateRect = updateRect.united( d->hoverTag->zoomedRect ); - if ( oldHoverTag ) - updateRect = updateRect.united( oldHoverTag->zoomedRect ); - - update( updateRect ); - } - } -} - - -void Nepomuk::TagCloud::leaveEvent( QEvent* ) -{ - unsetCursor(); - if ( d->hoverTag ) { - QRect updateRect = d->hoverTag->zoomedRect; - d->hoverTag = 0; - update( updateRect ); - } -} - - -void Nepomuk::TagCloud::slotStatementAdded( const Soprano::Statement& s ) -{ - if ( s.predicate().uri() == Soprano::Vocabulary::RDF::type() && - s.object().uri() == Nepomuk::Tag::resourceTypeUri() ) { - // new tag created - if ( d->showAllTags ) { - showAllTags(); - } - } - else if ( s.predicate().uri() == Nepomuk::Resource::tagUri() ) { - if ( s.subject().uri() == d->resource ) { - showResourceTags( d->resource ); - } - else { - // weights might have changed - d->updateNodeWeights(); - d->rebuildCloud(); - } - } -} - - -void Nepomuk::TagCloud::slotStatementRemoved( const Soprano::Statement& s ) -{ - // FIXME: In theory might contain empty nodes as wildcards - - if ( s.predicate().uri() == Nepomuk::Resource::tagUri() ) { - if ( d->resource.isValid() && - d->resource == s.subject().uri() ) { - showResourceTags( d->resource ); - } - else { - // weights might have changed - d->updateNodeWeights(); - d->rebuildCloud(); - } - } - else if ( s.predicate().uri() == Soprano::Vocabulary::RDF::type() && - s.object().uri() == Nepomuk::Tag::resourceTypeUri() ) { - // tag deleted - if ( d->showAllTags ) { - showAllTags(); - } - } -} - - -void Nepomuk::TagCloud::setCustomNewTagAction( QAction* action ) -{ - d->customNewTagAction = action; - setNewTagButtonEnabled( action != 0 ); -} - -#include "tagcloud.moc" diff --git a/src/tagcloud/tagcloud.h b/src/tagcloud/tagcloud.h deleted file mode 100644 index 9710ca9b7..000000000 --- a/src/tagcloud/tagcloud.h +++ /dev/null @@ -1,142 +0,0 @@ -/* - This file is part of the Nepomuk KDE project. - Copyright (C) 2007 Sebastian Trueg - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License version 2 as published by the Free Software Foundation. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - */ - -#ifndef _NEPOMUK_TAG_CLOUD_H_ -#define _NEPOMUK_TAG_CLOUD_H_ - -#include -#include - -#include - -#include - -class QResizeEvent; -class QPaintEvent; -class QMouseEvent; -class QEvent; - -namespace Nepomuk { - class TagCloud : public QFrame - { - Q_OBJECT - - public: - TagCloud( QWidget* parent = 0 ); - ~TagCloud(); - - enum Sorting { - SortAlpabetically, - SortByWeight, - SortRandom - }; - - int heightForWidth( int w ) const; - QSize sizeHint() const; - QSize minimumSizeHint() const; - - bool zoomEnabled() const; - - public Q_SLOTS: - /** - * Set the maximum used font size. The default is 0 - * which means to calculate proper values from the KDE - * defaults. - */ - void setMaxFontSize( int size ); - - /** - * Set the minimum used font size. The default is 0 - * which means to calculate proper values from the KDE - * defaults. - */ - void setMinFontSize( int size ); - - /** - * Set the maximum number of displayed tags. The default is 0 - * which means to display all tags. - * - * NOT IMPLEMENTED YET - */ - void setMaxNumberDisplayedTags( int n ); - - /** - * Allow selection of tags, i.e. enabling and disabling of tags. - */ - void setSelectionEnabled( bool enabled ); - - void setNewTagButtonEnabled( bool enabled ); - void setContextMenuEnabled( bool enabled ); - void setAlignment( Qt::Alignment alignment ); - - void setZoomEnabled( bool zoom ); - - /** - * Default: SortAlpabetically - */ - void setSorting( Sorting ); - - /** - * Will reset tags set via showTags() - */ - void showAllTags(); - - /** - * Set the tags to be shown in the tag cloud. - * If the new tag button is enabled (setEnableNewTagButton()) - * new tags will automatically be added to the list of shown tags. - */ - void showTags( const QList& tags ); - - void showResourceTags( const Resource& resource ); - - /** - * Select or deselect a tag. This does only make sense - * if selection is enabled and \p tag is actually - * displayed. - * - * \sa setSelectionEnabled - */ - void setTagSelected( const Tag& tag, bool selected ); - - void setCustomNewTagAction( QAction* action ); - - Q_SIGNALS: - void tagClicked( const Nepomuk::Tag& tag ); - void tagAdded( const Nepomuk::Tag& tag ); - void tagToggled( const Nepomuk::Tag& tag, bool enabled ); - - protected: - void resizeEvent( QResizeEvent* e ); - void paintEvent( QPaintEvent* e ); - void mousePressEvent( QMouseEvent* ); - void mouseMoveEvent( QMouseEvent* ); - void leaveEvent( QEvent* ); - - private Q_SLOTS: - void slotStatementAdded( const Soprano::Statement& s ); - void slotStatementRemoved( const Soprano::Statement& s ); - - private: - class Private; - Private* const d; - }; -} - -#endif diff --git a/src/tagcloud/taggingpopup.cpp b/src/tagcloud/taggingpopup.cpp deleted file mode 100644 index 3e59c80d1..000000000 --- a/src/tagcloud/taggingpopup.cpp +++ /dev/null @@ -1,147 +0,0 @@ -/* - This file is part of the Nepomuk KDE project. - Copyright (C) 2007 Sebastian Trueg - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License version 2 as published by the Free Software Foundation. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - */ - -#include "taggingpopup.h" - -#include -#include -#include -#include -#include - -#include -#include - - -class Nepomuk::TaggingPopup::Private -{ -public: - Private( TaggingPopup* parent ) - : eventLoop( 0 ), - m_parent( parent ) { - } - - QEventLoop* eventLoop; - QPoint popupPos; - - QRect geometryForPopupPos( const QPoint& p ) { - QSize size = m_parent->sizeHint(); - - // we want a little margin - const int margin = KDialog::marginHint(); - size.setHeight( size.height() + margin*2 ); - size.setWidth( size.width() + margin*2 ); - - QRect screen = QApplication::desktop()->screenGeometry( QApplication::desktop()->screenNumber( p ) ); - - // calculate popup position - QPoint pos( p.x() - size.width()/2, p.y() - size.height()/2 ); - - // ensure we do not leave the desktop - if ( pos.x() + size.width() > screen.right() ) { - pos.setX( screen.right() - size.width() ); - } - else if ( pos.x() < screen.left() ) { - pos.setX( screen.left() ); - } - - if ( pos.y() + size.height() > screen.bottom() ) { - pos.setY( screen.bottom() - size.height() ); - } - else if ( pos.y() < screen.top() ) { - pos.setY( screen.top() ); - } - - return QRect( pos, size ); - } - -private: - TaggingPopup* m_parent; -}; - - -Nepomuk::TaggingPopup::TaggingPopup( QWidget* parent ) - : TagCloud( parent ), - d( new Private( this ) ) -{ - setFrameStyle( QFrame::Box|QFrame::Plain ); - setWindowFlags( Qt::Popup ); -} - - -Nepomuk::TaggingPopup::~TaggingPopup() -{ - delete d; -} - - -void Nepomuk::TaggingPopup::popup( const QPoint& p ) -{ - setGeometry( d->geometryForPopupPos( p ) ); - d->popupPos = p; - - show(); -} - - -void Nepomuk::TaggingPopup::exec( const QPoint& pos ) -{ - QEventLoop eventLoop; - d->eventLoop = &eventLoop; - popup( pos ); - - QPointer guard = this; - (void) eventLoop.exec(); - if ( !guard.isNull() ) - d->eventLoop = 0; -} - - -void Nepomuk::TaggingPopup::mousePressEvent( QMouseEvent* e ) -{ - if ( !rect().contains( e->pos() ) ) { - hide(); - } - else { - TagCloud::mousePressEvent( e ); - } -} - - -void Nepomuk::TaggingPopup::hideEvent( QHideEvent* e ) -{ - Q_UNUSED( e ); - if ( d->eventLoop ) { - d->eventLoop->exit(); - } -} - - -bool Nepomuk::TaggingPopup::event( QEvent* e ) -{ - if ( e->type() == QEvent::LayoutRequest ) { - if ( isVisible() ) { - setGeometry( d->geometryForPopupPos( d->popupPos ) ); - return true; - } - } - - return TagCloud::event( e ); -} - diff --git a/src/tagcloud/taggingpopup.h b/src/tagcloud/taggingpopup.h deleted file mode 100644 index 99cee701c..000000000 --- a/src/tagcloud/taggingpopup.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - This file is part of the Nepomuk KDE project. - Copyright (C) 2007 Sebastian Trueg - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License version 2 as published by the Free Software Foundation. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - */ - -#ifndef _NEPOMUK_TAGGING_POPUP_H_ -#define _NEPOMUK_TAGGING_POPUP_H_ - -#include "tagcloud.h" - -class QMouseEvent; -class QHideEvent; - -namespace Nepomuk { - class TaggingPopup : public TagCloud - { - public: - TaggingPopup( QWidget* parent = 0 ); - ~TaggingPopup(); - - void popup( const QPoint& pos ); - void exec( const QPoint& pos ); - - bool event( QEvent* e ); - - protected: - void mousePressEvent( QMouseEvent* e ); - void hideEvent( QHideEvent* e ); - - private: - class Private; - Private* const d; - }; -} - -#endif diff --git a/src/terminalsidebarpage.cpp b/src/terminalsidebarpage.cpp deleted file mode 100644 index 4749e7714..000000000 --- a/src/terminalsidebarpage.cpp +++ /dev/null @@ -1,97 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2007 by Peter Penz * - * * - * 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 of the License, 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. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#include "terminalsidebarpage.h" - -#include -#include -#include -#include - -#include -#include - -TerminalSidebarPage::TerminalSidebarPage(QWidget* parent) : - SidebarPage(parent), - m_layout(0), - m_terminal(0), - m_terminalWidget(0) -{ - m_layout = new QVBoxLayout(this); - m_layout->setMargin(0); -} - -TerminalSidebarPage::~TerminalSidebarPage() -{ -} - -QSize TerminalSidebarPage::sizeHint() const -{ - QSize size = SidebarPage::sizeHint(); - size.setHeight(200); - return size; -} - -void TerminalSidebarPage::setUrl(const KUrl& url) -{ - if (!url.isValid() || (url == SidebarPage::url())) { - return; - } - - SidebarPage::setUrl(url); - if ((m_terminal != 0) && isVisible() && url.isLocalFile()) { - m_terminal->sendInput("cd " + KShell::quoteArg(url.path()) + '\n'); - } -} - -void TerminalSidebarPage::terminalExited() -{ - emit hideTerminalSidebarPage(); - - m_terminal = 0; -} - -void TerminalSidebarPage::showEvent(QShowEvent* event) -{ - if (event->spontaneous()) { - SidebarPage::showEvent(event); - return; - } - - if (m_terminal == 0) { - KPluginFactory* factory = KPluginLoader("libkonsolepart").factory(); - KParts::ReadOnlyPart* part = factory ? (factory->create(this)) : 0; - if (part != 0) { - connect(part, SIGNAL(destroyed(QObject*)), this, SLOT(terminalExited())); - m_terminalWidget = part->widget(); - m_layout->addWidget(m_terminalWidget); - m_terminal = qobject_cast(part); - m_terminal->showShellInDir(url().path()); - } - } - if (m_terminal != 0) { - m_terminal->sendInput("cd " + KShell::quoteArg(url().path()) + '\n'); - m_terminal->sendInput("clear\n"); - m_terminalWidget->setFocus(); - } - - SidebarPage::showEvent(event); -} - -#include "terminalsidebarpage.moc" diff --git a/src/terminalsidebarpage.h b/src/terminalsidebarpage.h deleted file mode 100644 index 875a6b706..000000000 --- a/src/terminalsidebarpage.h +++ /dev/null @@ -1,62 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2007 by Peter Penz * - * * - * 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 of the License, 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. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#ifndef TERMINALSIDEBARPAGE_H -#define TERMINALSIDEBARPAGE_H - -#include - -class TerminalInterface; -class QVBoxLayout; -class QWidget; - -/** - * @brief Shows the terminal which is synchronized with the URL of the - * active view. - */ -class TerminalSidebarPage : public SidebarPage -{ - Q_OBJECT - -public: - TerminalSidebarPage(QWidget* parent = 0); - virtual ~TerminalSidebarPage(); - - /** @see QWidget::sizeHint() */ - virtual QSize sizeHint() const; - -public slots: - /** @see SidebarPage::setUrl(). */ - virtual void setUrl(const KUrl& url); - void terminalExited(); - -signals: - void hideTerminalSidebarPage(); - -protected: - /** @see QWidget::showEvent() */ - virtual void showEvent(QShowEvent* event); - -private: - QVBoxLayout* m_layout; - TerminalInterface* m_terminal; - QWidget* m_terminalWidget; -}; - -#endif // TERMINALSIDEBARPAGE_H diff --git a/src/tooltipmanager.cpp b/src/tooltipmanager.cpp deleted file mode 100644 index aefa846e9..000000000 --- a/src/tooltipmanager.cpp +++ /dev/null @@ -1,307 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2008 by Konstantin Heil * - * * - * 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 of the License, 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. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - *******************************************************************************/ - -#include "tooltipmanager.h" - -#include "dolphintooltip.h" -#include "dolphinmodel.h" -#include "dolphinsortfilterproxymodel.h" - -#include -#include -#include - -#include -#include -#include -#include -#include - -const int ICON_WIDTH = 128; -const int ICON_HEIGHT = 128; -const int PREVIEW_DELAY = 250; - -K_GLOBAL_STATIC(DolphinBalloonTooltipDelegate, g_delegate) - -ToolTipManager::ToolTipManager(QAbstractItemView* parent, - DolphinSortFilterProxyModel* model) : - QObject(parent), - m_view(parent), - m_dolphinModel(0), - m_proxyModel(model), - m_timer(0), - m_previewTimer(0), - m_waitOnPreviewTimer(0), - m_item(), - m_itemRect(), - m_preview(false), - m_generatingPreview(false), - m_previewIsLate(false), - m_previewPass(0), - m_emptyRenderedKToolTipItem(0), - m_pix() -{ - KToolTip::setToolTipDelegate(g_delegate); - - m_dolphinModel = static_cast(m_proxyModel->sourceModel()); - connect(parent, SIGNAL(entered(const QModelIndex&)), - this, SLOT(requestToolTip(const QModelIndex&))); - connect(parent, SIGNAL(viewportEntered()), - this, SLOT(hideToolTip())); - - m_timer = new QTimer(this); - m_timer->setSingleShot(true); - connect(m_timer, SIGNAL(timeout()), - this, SLOT(prepareToolTip())); - - m_previewTimer = new QTimer(this); - m_previewTimer->setSingleShot(true); - connect(m_previewTimer, SIGNAL(timeout()), - this, SLOT(startPreviewJob())); - - m_waitOnPreviewTimer = new QTimer(this); - m_waitOnPreviewTimer->setSingleShot(true); - connect(m_waitOnPreviewTimer, SIGNAL(timeout()), - this, SLOT(prepareToolTip())); - - // When the mousewheel is used, the items don't get a hovered indication - // (Qt-issue #200665). To assure that the tooltip still gets hidden, - // the scrollbars are observed. - connect(parent->horizontalScrollBar(), SIGNAL(valueChanged(int)), - this, SLOT(hideTip())); - connect(parent->verticalScrollBar(), SIGNAL(valueChanged(int)), - this, SLOT(hideTip())); - - m_view->viewport()->installEventFilter(this); -} - -ToolTipManager::~ToolTipManager() -{ -} - -void ToolTipManager::hideTip() -{ - hideToolTip(); -} - -bool ToolTipManager::eventFilter(QObject* watched, QEvent* event) -{ - if ((watched == m_view->viewport()) && (event->type() == QEvent::Leave)) { - hideToolTip(); - } - - return QObject::eventFilter(watched, event); -} - -void ToolTipManager::requestToolTip(const QModelIndex& index) -{ - // only request a tooltip for the name column and when no selection or - // drag & drop operation is done (indicated by the left mouse button) - if ((index.column() == DolphinModel::Name) && !(QApplication::mouseButtons() & Qt::LeftButton)) { - m_waitOnPreviewTimer->stop(); - KToolTip::hideTip(); - - m_itemRect = m_view->visualRect(index); - const QPoint pos = m_view->viewport()->mapToGlobal(m_itemRect.topLeft()); - m_itemRect.moveTo(pos); - - const QModelIndex dirIndex = m_proxyModel->mapToSource(index); - m_item = m_dolphinModel->itemForIndex(dirIndex); - - // only start the previewJob when the mouse has been over this item for 200 milliseconds, - // this prevents a lot of useless preview jobs when passing rapidly over a lot of items - m_previewTimer->start(200); - m_preview = false; - m_previewIsLate = false; - m_previewPass = 0; - - m_timer->start(500); - } else { - hideToolTip(); - } -} - -void ToolTipManager::hideToolTip() -{ - m_timer->stop(); - m_previewTimer->stop(); - m_waitOnPreviewTimer->stop(); - m_previewIsLate = false; - KToolTip::hideTip(); -} - -void ToolTipManager::prepareToolTip() -{ - if (m_generatingPreview) { - if (m_previewPass == 1) { - // We waited 250msec and the preview is still not finished, - // so show the toolTip with a transparent image of maximal width. - // When the preview finishes, m_previewIsLate will cause - // a direct update of the tooltip, via m_emptyRenderedKToolTipItem. - QPixmap paddedImage(QSize(PREVIEW_WIDTH, 32)); - m_previewIsLate = true; - paddedImage.fill(Qt::transparent); - KToolTipItem* toolTip = new KToolTipItem(paddedImage, m_item.getToolTipText()); - m_emptyRenderedKToolTipItem = toolTip; // make toolTip accessible everywhere - showToolTip(toolTip); - } - - ++m_previewPass; - m_waitOnPreviewTimer->start(250); - } else { - // The preview generation has finished, find out under which circumstances. - if (m_preview && m_previewIsLate) { - // We got a preview, but it is late, the tooltip has already been shown. - // So update the tooltip directly. - if (m_emptyRenderedKToolTipItem != 0) { - m_emptyRenderedKToolTipItem->setData(Qt::DecorationRole, KIcon(m_pix)); - } - return; - } - - KIcon icon; - if (m_preview) { - // We got a preview. - icon = KIcon(m_pix); - } else { - // No preview, so use an icon. - // Force a 128x128 icon, a 256x256 one is far too big. - icon = KIcon(KIcon(m_item.iconName()).pixmap(ICON_WIDTH, ICON_HEIGHT)); - } - - KToolTipItem* toolTip = new KToolTipItem(icon, m_item.getToolTipText()); - showToolTip(toolTip); - } -} - -void ToolTipManager::showToolTip(KToolTipItem* tip) -{ - if (QApplication::mouseButtons() & Qt::LeftButton) { - delete tip; - tip = 0; - // m_emptyRenderedKToolTipItem is an alias for tip. - m_emptyRenderedKToolTipItem = 0; - return; - } - - KStyleOptionToolTip option; - // TODO: get option content from KToolTip or add KToolTip::sizeHint() method - option.direction = QApplication::layoutDirection(); - option.fontMetrics = QFontMetrics(QToolTip::font()); - option.activeCorner = KStyleOptionToolTip::TopLeftCorner; - option.palette = QToolTip::palette(); - option.font = QToolTip::font(); - option.rect = QRect(); - option.state = QStyle::State_None; - option.decorationSize = QSize(32, 32); - - QSize size; - if (m_previewIsLate) { - QPixmap paddedImage(QSize(PREVIEW_WIDTH, PREVIEW_HEIGHT)); - KToolTipItem* maxiTip = new KToolTipItem(paddedImage, m_item.getToolTipText()); - size = g_delegate->sizeHint(&option, maxiTip); - delete maxiTip; - maxiTip = 0; - } - else { - size = g_delegate->sizeHint(&option, tip); - } - const QRect desktop = QApplication::desktop()->screenGeometry(m_itemRect.bottomRight()); - - // m_itemRect defines the area of the item, where the tooltip should be - // shown. Per default the tooltip is shown in the bottom right corner. - // If the tooltip content exceeds the desktop borders, it must be assured that: - // - the content is fully visible - // - the content is not drawn inside m_itemRect - const bool hasRoomToLeft = (m_itemRect.left() - size.width() >= desktop.left()); - const bool hasRoomToRight = (m_itemRect.right() + size.width() <= desktop.right()); - const bool hasRoomAbove = (m_itemRect.top() - size.height() >= desktop.top()); - const bool hasRoomBelow = (m_itemRect.bottom() + size.height() <= desktop.bottom()); - if (!hasRoomAbove && !hasRoomBelow && !hasRoomToLeft && !hasRoomToRight) { - delete tip; - tip = 0; - return; - } - - int x = 0; - int y = 0; - if (hasRoomBelow || hasRoomAbove) { - x = QCursor::pos().x() + 16; // TODO: use mouse pointer width instead of the magic value of 16 - if (x + size.width() >= desktop.right()) { - x = desktop.right() - size.width(); - } - y = hasRoomBelow ? m_itemRect.bottom() : m_itemRect.top() - size.height(); - } else { - Q_ASSERT(hasRoomToLeft || hasRoomToRight); - x = hasRoomToRight ? m_itemRect.right() : m_itemRect.left() - size.width(); - - // Put the tooltip at the bottom of the screen. The x-coordinate has already - // been adjusted, so that no overlapping with m_itemRect occurs. - y = desktop.bottom() - size.height(); - } - - KToolTip::showTip(QPoint(x, y), tip); -} - - - -void ToolTipManager::startPreviewJob() -{ - m_generatingPreview = true; - KIO::PreviewJob* job = KIO::filePreview(KFileItemList() << m_item, - PREVIEW_WIDTH, - PREVIEW_HEIGHT); - job->setIgnoreMaximumSize(true); - - connect(job, SIGNAL(gotPreview(const KFileItem&, const QPixmap&)), - this, SLOT(setPreviewPix(const KFileItem&, const QPixmap&))); - connect(job, SIGNAL(failed(const KFileItem&)), - this, SLOT(previewFailed(const KFileItem&))); -} - - -void ToolTipManager::setPreviewPix(const KFileItem& item, - const QPixmap& pixmap) -{ - if (m_item.url() != item.url()) { - m_generatingPreview = false; - return; - } - - if (m_previewIsLate) { - // always use the maximal width - QPixmap paddedImage(QSize(PREVIEW_WIDTH, pixmap.height())); - paddedImage.fill(Qt::transparent); - QPainter painter(&paddedImage); - painter.drawPixmap((PREVIEW_WIDTH - pixmap.width()) / 2, 0, pixmap); - m_pix = paddedImage; - } else { - m_pix = pixmap; - } - m_preview = true; - m_generatingPreview = false; -} - -void ToolTipManager::previewFailed(const KFileItem& item) -{ - Q_UNUSED(item); - m_generatingPreview = false; -} - -#include "tooltipmanager.moc" diff --git a/src/tooltipmanager.h b/src/tooltipmanager.h deleted file mode 100644 index 96df4819e..000000000 --- a/src/tooltipmanager.h +++ /dev/null @@ -1,91 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2008 by Konstantin Heil * - * * - * 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 of the License, 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. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - *******************************************************************************/ - -#ifndef TOOLTIPMANAGER_H -#define TOOLTIPMANAGER_H - -#include -#include - -#include - -class DolphinModel; -class DolphinSortFilterProxyModel; -class QAbstractItemView; -class QModelIndex; -class QTimer; -class KToolTipItem; - -/** - * @brief Manages the tooltips for an item view. - * - * When hovering an item, a tooltip is shown after - * a short timeout. The tooltip is hidden again when the - * viewport is hovered or the item view has been left. - */ -class ToolTipManager : public QObject -{ - Q_OBJECT - -public: - explicit ToolTipManager(QAbstractItemView* parent, - DolphinSortFilterProxyModel* model); - virtual ~ToolTipManager(); - -public slots: - /** - * Hides the currently shown tooltip. Invoking this method is - * only needed when the tooltip should be hidden although - * an item is hovered. - */ - void hideTip(); - -protected: - virtual bool eventFilter(QObject* watched, QEvent* event); - -private slots: - void requestToolTip(const QModelIndex& index); - void hideToolTip(); - void prepareToolTip(); - void startPreviewJob(); - void setPreviewPix(const KFileItem& item, const QPixmap& pix); - void previewFailed(const KFileItem& item); - -private: - void showToolTip(KToolTipItem* tip); - - QAbstractItemView* m_view; - DolphinModel* m_dolphinModel; - DolphinSortFilterProxyModel* m_proxyModel; - - QTimer* m_timer; - QTimer* m_previewTimer; - QTimer* m_waitOnPreviewTimer; - KFileItem m_item; - QRect m_itemRect; - bool m_preview; - bool m_generatingPreview; - bool m_previewIsLate; - int m_previewPass; - KToolTipItem* m_emptyRenderedKToolTipItem; - QPixmap m_pix; - -}; - -#endif diff --git a/src/tooltips/dolphintooltip.cpp b/src/tooltips/dolphintooltip.cpp new file mode 100644 index 000000000..bc3be33aa --- /dev/null +++ b/src/tooltips/dolphintooltip.cpp @@ -0,0 +1,50 @@ +/*************************************************************************** + * Copyright (C) 2008 by Simon St James * + * * + * 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 of the License, 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. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#include "dolphintooltip.h" + +#include +#include +#include + +#include + +DolphinBalloonTooltipDelegate::DolphinBalloonTooltipDelegate() +{ +} + +DolphinBalloonTooltipDelegate::~DolphinBalloonTooltipDelegate() +{ +} + +// Delegate everything to the base class, after re-setting the decorationSize +// to the preview size. +QSize DolphinBalloonTooltipDelegate::sizeHint(const KStyleOptionToolTip* option, const KToolTipItem* item) const +{ + KStyleOptionToolTip updatedStyleOption = *option; + updatedStyleOption.decorationSize = QSize(PREVIEW_WIDTH, PREVIEW_HEIGHT); + return KFormattedBalloonTipDelegate::sizeHint(&updatedStyleOption, item); +} + +void DolphinBalloonTooltipDelegate::paint(QPainter* painter, const KStyleOptionToolTip* option, const KToolTipItem* item) const +{ + KStyleOptionToolTip updatedStyleOption = *option; + updatedStyleOption.decorationSize = QSize(PREVIEW_WIDTH, PREVIEW_HEIGHT); + return KFormattedBalloonTipDelegate::paint(painter, &updatedStyleOption, item); +} diff --git a/src/tooltips/dolphintooltip.h b/src/tooltips/dolphintooltip.h new file mode 100644 index 000000000..5c0682171 --- /dev/null +++ b/src/tooltips/dolphintooltip.h @@ -0,0 +1,47 @@ +/*************************************************************************** + * Copyright (C) 2008 by Simon St James * + * * + * 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 of the License, 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. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +// NOTE: proper documentation will be added once the code is better developed. + +#ifndef DOLPHINTOOLTIP_H +#define DOLPHINTOOLTIP_H + +#include +#include + +#include +#include + +class KFileItem; +class QPixmap; + +const int PREVIEW_WIDTH = 256; +const int PREVIEW_HEIGHT = 256; + + +class DolphinBalloonTooltipDelegate : public KFormattedBalloonTipDelegate +{ +public: + DolphinBalloonTooltipDelegate(); + virtual ~DolphinBalloonTooltipDelegate(); + + virtual QSize sizeHint(const KStyleOptionToolTip* option, const KToolTipItem* item) const; + virtual void paint(QPainter* painter, const KStyleOptionToolTip* option, const KToolTipItem* item) const; +}; +#endif diff --git a/src/tooltips/kformattedballoontipdelegate.cpp b/src/tooltips/kformattedballoontipdelegate.cpp new file mode 100644 index 000000000..140c90ef4 --- /dev/null +++ b/src/tooltips/kformattedballoontipdelegate.cpp @@ -0,0 +1,129 @@ +/******************************************************************************* + * Copyright (C) 2008 by Fredrik Höglund * + * Copyright (C) 2008 by Konstantin Heil * + * * + * 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 of the License, 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. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + *******************************************************************************/ + +#include "kformattedballoontipdelegate.h" +#include +#include +#include +#include + +KFormattedBalloonTipDelegate::KFormattedBalloonTipDelegate() +{ +} + +KFormattedBalloonTipDelegate::~KFormattedBalloonTipDelegate() +{ +} + +QSize KFormattedBalloonTipDelegate::sizeHint(const KStyleOptionToolTip *option, const KToolTipItem *item) const +{ + QTextDocument doc; + doc.setHtml(item->text()); + const QIcon icon = item->icon(); + + const QSize iconSize = icon.isNull() ? QSize(0, 0) : icon.actualSize(option->decorationSize); + const QSize docSize = doc.size().toSize(); + QSize contentSize = iconSize + docSize; + + // assure that the content height is large enough for the icon and the document + contentSize.setHeight(iconSize.height() > doc.size().height() ? iconSize.height() : doc.size().height()); + return contentSize + QSize(Border * 3, Border * 2); +} + +void KFormattedBalloonTipDelegate::paint(QPainter *painter, + const KStyleOptionToolTip *option, + const KToolTipItem *item) const +{ + QPainterPath path = createPath(*option); + if (haveAlphaChannel()) { + painter->setRenderHint(QPainter::Antialiasing); + painter->translate(.5, .5); + } + + const QColor toColor = option->palette.brush(QPalette::ToolTipBase).color(); + const QColor fromColor = KColorScheme::shade(toColor, KColorScheme::LightShade, 0.2); + + QLinearGradient gradient(option->rect.topLeft(), option->rect.bottomLeft()); + gradient.setColorAt(0.0, fromColor); + gradient.setColorAt(1.0, toColor); + painter->setPen(Qt::NoPen); + painter->setBrush(gradient); + + painter->drawPath(path); + + const QIcon icon = item->icon(); + int x = Border; + const int y = Border; + if (!icon.isNull()) { + const QSize iconSize = icon.actualSize(option->decorationSize); + const QPoint pos(x + option->rect.x(), y + option->rect.y()); + painter->drawPixmap(pos, icon.pixmap(iconSize)); + x += iconSize.width() + Border; + } + + QTextDocument doc; + doc.setHtml(item->text()); + QPixmap bitmap(doc.size().toSize()); + bitmap.fill(Qt::transparent); + QPainter p(&bitmap); + doc.drawContents(&p); + + const QRect docRect(QPoint(x, y), doc.size().toSize()); + painter->drawPixmap(docRect, bitmap); +} + +QRegion KFormattedBalloonTipDelegate::inputShape(const KStyleOptionToolTip *option) const +{ + QBitmap bitmap(option->rect.size()); + bitmap.fill(Qt::color0); + + QPainter p(&bitmap); + p.setPen(QPen(Qt::color1, 1)); + p.setBrush(Qt::color1); + p.drawPath(createPath(*option)); + + return QRegion(bitmap); +} + +QRegion KFormattedBalloonTipDelegate::shapeMask(const KStyleOptionToolTip *option) const +{ + return inputShape(option); +} + +static inline void arc(QPainterPath &path, qreal cx, qreal cy, qreal radius, qreal angle, qreal sweeplength) +{ + path.arcTo(cx-radius, cy-radius, radius * 2, radius * 2, angle, sweeplength); +} + +QPainterPath KFormattedBalloonTipDelegate::createPath(const KStyleOptionToolTip& option) const +{ + const QRect rect = option.rect; + const qreal radius = 5; + + QPainterPath path; + path.moveTo(rect.left(), rect.top() + radius); + arc(path, rect.left() + radius, rect.top() + radius, radius, 180, -90); + arc(path, rect.right() - radius, rect.top() + radius, radius, 90, -90); + arc(path, rect.right() - radius, rect.bottom() - radius, radius, 0, -90); + arc(path, rect.left() + radius, rect.bottom() - radius, radius, 270, -90); + path.closeSubpath(); + + return path; +} diff --git a/src/tooltips/kformattedballoontipdelegate.h b/src/tooltips/kformattedballoontipdelegate.h new file mode 100644 index 000000000..117d6eec7 --- /dev/null +++ b/src/tooltips/kformattedballoontipdelegate.h @@ -0,0 +1,45 @@ +/******************************************************************************* + * Copyright (C) 2008 by Fredrik Höglund * + * Copyright (C) 2008 by Konstantin Heil * + * * + * 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 of the License, 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. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + *******************************************************************************/ + +#ifndef KFORMATTEDBALLOONTIPDELEGATE_H +#define KFORMATTEDBALLOONTIPDELEGATE_H + +#include +#include + +class KFormattedBalloonTipDelegate : public KToolTipDelegate +{ +public: + KFormattedBalloonTipDelegate(); + virtual ~KFormattedBalloonTipDelegate(); + + virtual QSize sizeHint(const KStyleOptionToolTip *option, const KToolTipItem *item) const; + virtual void paint(QPainter *painter, const KStyleOptionToolTip *option, const KToolTipItem *item) const; + virtual QRegion inputShape(const KStyleOptionToolTip *option) const; + virtual QRegion shapeMask(const KStyleOptionToolTip *option) const; + +private: + QPainterPath createPath(const KStyleOptionToolTip& option) const; + +private: + enum { Border = 8 }; +}; + +#endif diff --git a/src/tooltips/ktooltip.cpp b/src/tooltips/ktooltip.cpp new file mode 100644 index 000000000..a0126fbff --- /dev/null +++ b/src/tooltips/ktooltip.cpp @@ -0,0 +1,558 @@ +/*************************************************************************** + * Copyright (C) 2008 by Fredrik Höglund * + * * + * 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 of the License, 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. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#include "ktooltip.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef Q_WS_X11 +# include +# include +# include +# include +#endif + +#include "ktooltip_p.h" + + +// compile with XShape older than 1.0 +#ifndef ShapeInput +const int ShapeInput = 2; +#endif + + +class KToolTipItemPrivate +{ +public: + QMap map; + int type; +}; + +KToolTipItem::KToolTipItem(const QString &text, int type) + : d(new KToolTipItemPrivate) +{ + d->map[Qt::DisplayRole] = text; + d->type = type; +} + +KToolTipItem::KToolTipItem(const QIcon &icon, const QString &text, int type) + : d(new KToolTipItemPrivate) +{ + d->map[Qt::DecorationRole] = icon; + d->map[Qt::DisplayRole] = text; + d->type = type; +} + +KToolTipItem::~KToolTipItem() +{ + delete d; +} + +int KToolTipItem::type() const +{ + return d->type; +} + +QString KToolTipItem::text() const +{ + return data(Qt::DisplayRole).toString(); +} + +QIcon KToolTipItem::icon() const +{ + return qvariant_cast(data(Qt::DecorationRole)); +} + +QVariant KToolTipItem::data(int role) const +{ + return d->map.value(role); +} + +void KToolTipItem::setData(int role, const QVariant &data) +{ + d->map[role] = data; + KToolTipManager::instance()->update(); +} + + + +// ---------------------------------------------------------------------------- + + +KStyleOptionToolTip::KStyleOptionToolTip() + : fontMetrics(QApplication::font()) +{ +} + + +// ---------------------------------------------------------------------------- + + + +KToolTipDelegate::KToolTipDelegate() : QObject() +{ +} + +KToolTipDelegate::~KToolTipDelegate() +{ +} + +QSize KToolTipDelegate::sizeHint(const KStyleOptionToolTip *option, const KToolTipItem *item) const +{ + QSize size; + size.rwidth() = option->fontMetrics.width(item->text()); + size.rheight() = option->fontMetrics.lineSpacing(); + + QIcon icon = item->icon(); + if (!icon.isNull()) { + const QSize iconSize = icon.actualSize(option->decorationSize); + size.rwidth() += iconSize.width() + 4; + size.rheight() = qMax(size.height(), iconSize.height()); + } + + return size + QSize(20, 20); + +} + +void KToolTipDelegate::paint(QPainter *painter, const KStyleOptionToolTip *option, + const KToolTipItem *item) const +{ + bool haveAlpha = haveAlphaChannel(); + painter->setRenderHint(QPainter::Antialiasing); + + QPainterPath path; + if (haveAlpha) + path.addRoundRect(option->rect.adjusted(0, 0, -1, -1), 25); + else + path.addRect(option->rect.adjusted(0, 0, -1, -1)); + + QColor color = option->palette.color(QPalette::ToolTipBase); + QColor from = color.lighter(105); + QColor to = color.darker(120); + + QLinearGradient gradient(0, 0, 0, 1); + gradient.setCoordinateMode(QGradient::ObjectBoundingMode); + gradient.setColorAt(0, from); + gradient.setColorAt(1, to); + + painter->translate(.5, .5); + painter->setPen(QPen(Qt::black, 1)); + painter->setBrush(gradient); + painter->drawPath(path); + painter->translate(-.5, -.5); + + if (haveAlpha) { + QLinearGradient mask(0, 0, 0, 1); + gradient.setCoordinateMode(QGradient::ObjectBoundingMode); + gradient.setColorAt(0, QColor(0, 0, 0, 192)); + gradient.setColorAt(1, QColor(0, 0, 0, 72)); + painter->setCompositionMode(QPainter::CompositionMode_DestinationIn); + painter->fillRect(option->rect, gradient); + painter->setCompositionMode(QPainter::CompositionMode_SourceOver); + } + + QRect textRect = option->rect.adjusted(10, 10, -10, -10); + + QIcon icon = item->icon(); + if (!icon.isNull()) { + const QSize iconSize = icon.actualSize(option->decorationSize); + painter->drawPixmap(textRect.topLeft(), icon.pixmap(iconSize)); + textRect.adjust(iconSize.width() + 4, 0, 0, 0); + } + painter->drawText(textRect, Qt::AlignLeft | Qt::AlignVCenter, item->text()); +} + +QRegion KToolTipDelegate::inputShape(const KStyleOptionToolTip *option) const +{ + return QRegion(option->rect); +} + +QRegion KToolTipDelegate::shapeMask(const KStyleOptionToolTip *option) const +{ + return QRegion(option->rect); +} + +bool KToolTipDelegate::haveAlphaChannel() const +{ + return KToolTipManager::instance()->haveAlphaChannel(); +} + + + +// ---------------------------------------------------------------------------- + + + +class KAbstractToolTipLabel +{ +public: + KAbstractToolTipLabel() {} + virtual ~KAbstractToolTipLabel() {} + + virtual void showTip(const QPoint &pos, const KToolTipItem *item) = 0; + virtual void moveTip(const QPoint &pos) = 0; + virtual void hideTip() = 0; + +protected: + KStyleOptionToolTip styleOption() const; + KToolTipDelegate *delegate() const; +}; + +KStyleOptionToolTip KAbstractToolTipLabel::styleOption() const +{ + KStyleOptionToolTip option; + KToolTipManager::instance()->initStyleOption(&option); + return option; +} + +KToolTipDelegate *KAbstractToolTipLabel::delegate() const +{ + return KToolTipManager::instance()->delegate(); +} + + +// ---------------------------------------------------------------------------- + + + +class QWidgetLabel : public QWidget, public KAbstractToolTipLabel +{ +public: + QWidgetLabel() : QWidget(0, Qt::ToolTip) {} + void showTip(const QPoint &pos, const KToolTipItem *item); + void moveTip(const QPoint &pos); + void hideTip(); + +private: + void paintEvent(QPaintEvent*); + QSize sizeHint() const; + +private: + const KToolTipItem *currentItem; +}; + +void QWidgetLabel::showTip(const QPoint &pos, const KToolTipItem *item) +{ + currentItem = item; + move(pos); + show(); +} + +void QWidgetLabel::hideTip() +{ + hide(); + currentItem = 0; +} + +void QWidgetLabel::moveTip(const QPoint &pos) +{ + move(pos); +} + +void QWidgetLabel::paintEvent(QPaintEvent*) +{ + KStyleOptionToolTip option = styleOption(); + option.rect = rect(); + + setMask(delegate()->shapeMask(&option)); + + QPainter p(this); + p.setFont(option.font); + p.setPen(QPen(option.palette.brush(QPalette::Text), 0)); + delegate()->paint(&p, &option, currentItem); +} + +QSize QWidgetLabel::sizeHint() const +{ + if (!currentItem) + return QSize(); + + KStyleOptionToolTip option = styleOption(); + return delegate()->sizeHint(&option, currentItem); +} + + + +// ---------------------------------------------------------------------------- + + + +#ifdef Q_WS_X11 + +// X11 specific label that displays the tip in an ARGB window. +class ArgbLabel : public KAbstractToolTipLabel +{ +public: + ArgbLabel(Visual *visual, int depth); + ~ArgbLabel(); + + void showTip(const QPoint &pos, const KToolTipItem *item); + void moveTip(const QPoint &pos); + void hideTip(); + +private: + Window window; + Colormap colormap; + Picture picture; + bool mapped; +}; + +ArgbLabel::ArgbLabel(Visual *visual, int depth) +{ + Display *dpy = QX11Info::display(); + Window root = QX11Info::appRootWindow(); + colormap = XCreateColormap(dpy, QX11Info::appRootWindow(), visual, AllocNone); + + XSetWindowAttributes attr; + attr.border_pixel = 0; + attr.background_pixel = 0; + attr.colormap = colormap; + attr.override_redirect = True; + + window = XCreateWindow(dpy, root, 0, 0, 1, 1, 0, depth, InputOutput, visual, + CWBorderPixel | CWBackPixel | CWColormap | + CWOverrideRedirect, &attr); + + // ### TODO: Set the WM hints so KWin can identify this window as a + // tooltip. + + XRenderPictFormat *format = XRenderFindVisualFormat(dpy, visual); + picture = XRenderCreatePicture(dpy, window, format, 0, 0); + + mapped = false; +} + +ArgbLabel::~ArgbLabel() +{ + Display *dpy = QX11Info::display(); + XRenderFreePicture(dpy, picture); + XDestroyWindow(dpy, window); + XFreeColormap(dpy, colormap); +} + +void ArgbLabel::showTip(const QPoint &pos, const KToolTipItem *item) +{ + Display *dpy = QX11Info::display(); + KStyleOptionToolTip option = styleOption(); + const QSize size = delegate()->sizeHint(&option, item); + option.rect = QRect(QPoint(), size); + + QPixmap pixmap(size); + pixmap.fill(Qt::transparent); + + QPainter p(&pixmap); + p.setFont(option.font); + p.setPen(QPen(option.palette.brush(QPalette::Text), 0)); + delegate()->paint(&p, &option, item); + + // Resize, position and show the window. + XMoveResizeWindow(dpy, window, pos.x(), pos.y(), size.width(), size.height()); + + if (KToolTipManager::instance()->haveAlphaChannel()) { + const QRegion region = delegate()->inputShape(&option); + XShapeCombineRegion(dpy, window, ShapeInput, 0, 0, region.handle(), ShapeSet); + } else { + const QRegion region = delegate()->shapeMask(&option); + XShapeCombineRegion(dpy, window, ShapeBounding, 0, 0, region.handle(), ShapeSet); + } + + XMapWindow(dpy, window); + + // Blit the pixmap with the tip contents to the window. + // Since the window is override-redirect and an ARGB32 window, + // which always has an offscreen pixmap, there's no need to + // wait for an Expose event, or to process those. + XRenderComposite(dpy, PictOpSrc, pixmap.x11PictureHandle(), None, + picture, 0, 0, 0, 0, 0, 0, size.width(), size.height()); + + mapped = true; +} + +void ArgbLabel::moveTip(const QPoint &pos) +{ + if (mapped) + XMoveWindow(QX11Info::display(), window, pos.x(), pos.y()); +} + +void ArgbLabel::hideTip() +{ + if (mapped) { + Display *dpy = QX11Info::display(); + XUnmapWindow(dpy, window); + mapped = false; + } +} + +#endif // Q_WS_X11 + + + + +// ---------------------------------------------------------------------------- + + + + +KToolTipManager *KToolTipManager::s_instance = 0; + +KToolTipManager::KToolTipManager() + : label(0), currentItem(0), m_delegate(0) +{ +#ifdef Q_WS_X11 + Display *dpy = QX11Info::display(); + int screen = DefaultScreen(dpy); + int depth = DefaultDepth(dpy, screen); + Visual *visual = DefaultVisual(dpy, screen); + net_wm_cm_s0 = XInternAtom(dpy, "_NET_WM_CM_S0", False); + haveArgbVisual = false; + + int nvi; + XVisualInfo templ; + templ.screen = screen; + templ.depth = 32; + templ.c_class = TrueColor; + XVisualInfo *xvi = XGetVisualInfo(dpy, VisualScreenMask | VisualDepthMask | + VisualClassMask, &templ, &nvi); + + for (int i = 0; i < nvi; ++i) + { + XRenderPictFormat *format = XRenderFindVisualFormat(dpy, xvi[i].visual); + if (format->type == PictTypeDirect && format->direct.alphaMask) + { + visual = xvi[i].visual; + depth = xvi[i].depth; + haveArgbVisual = true; + break; + } + } + + if (haveArgbVisual) + label = new ArgbLabel(visual, depth); + else +#endif + label = new QWidgetLabel(); +} + +KToolTipManager::~KToolTipManager() +{ + delete label; + delete currentItem; +} + +void KToolTipManager::showTip(const QPoint &pos, KToolTipItem *item) +{ + hideTip(); + label->showTip(pos, item); + currentItem = item; + m_tooltipPos = pos; +} + +void KToolTipManager::hideTip() +{ + label->hideTip(); + delete currentItem; + currentItem = 0; +} + +void KToolTipManager::initStyleOption(KStyleOptionToolTip *option) const +{ + option->direction = QApplication::layoutDirection(); + option->fontMetrics = QFontMetrics(QToolTip::font()); + option->activeCorner = KStyleOptionToolTip::TopLeftCorner; + option->palette = QToolTip::palette(); + option->font = QToolTip::font(); + option->rect = QRect(); + option->state = QStyle::State_None; + option->decorationSize = QSize(32, 32); +} + +bool KToolTipManager::haveAlphaChannel() const +{ +#ifdef Q_WS_X11 + // ### This is a synchronous call - ideally we'd use a selection + // watcher to avoid it. + return haveArgbVisual && + XGetSelectionOwner(QX11Info::display(), net_wm_cm_s0) != None; +#else + return false; +#endif +} + +void KToolTipManager::setDelegate(KToolTipDelegate *delegate) +{ + m_delegate = delegate; +} + +void KToolTipManager::update() +{ + if (currentItem == 0) + return; + label->showTip(m_tooltipPos, currentItem); +} + +KToolTipDelegate *KToolTipManager::delegate() const +{ + return m_delegate; +} + + + +// ---------------------------------------------------------------------------- + + + +namespace KToolTip +{ + void showText(const QPoint &pos, const QString &text, QWidget *widget, const QRect &rect) + { + Q_UNUSED(widget) + Q_UNUSED(rect) + KToolTipItem *item = new KToolTipItem(text); + KToolTipManager::instance()->showTip(pos, item); + } + + void showText(const QPoint &pos, const QString &text, QWidget *widget) + { + showText(pos, text, widget, QRect()); + } + + void showTip(const QPoint &pos, KToolTipItem *item) + { + KToolTipManager::instance()->showTip(pos, item); + } + + void hideTip() + { + KToolTipManager::instance()->hideTip(); + } + + void setToolTipDelegate(KToolTipDelegate *delegate) + { + KToolTipManager::instance()->setDelegate(delegate); + } +} + diff --git a/src/tooltips/ktooltip.h b/src/tooltips/ktooltip.h new file mode 100644 index 000000000..d59f1bf17 --- /dev/null +++ b/src/tooltips/ktooltip.h @@ -0,0 +1,198 @@ +/*************************************************************************** + * Copyright (C) 2008 by Fredrik Höglund * + * * + * 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 of the License, 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. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#ifndef KTOOLTIP_H +#define KTOOLTIP_H + +#include +#include +#include +#include +#include +#include + +class QString; +class QIcon; +class QSize; +class QPainter; +class QRegion; + +class KToolTipItemPrivate; + +/** + * KToolTipItem contains the data to be displayed in a tooltip. + * + * Custom data can be stored as QVariants in the object by calling + * setData() with a custom item role, and retrieved and displayed + * by a tooltip delegate by calling data(). + * + * The default tooltip delegate uses Qt::DecorationRole and + * Qt::DisplayRole. + * + * To display the tooltip, call KToolTip::showTip() with a pointer + * to the KToolTipItem. + * + * You can reimplement the setData() and/or data() methods in this + * class to implement on-demand loading of data. + */ +class KToolTipItem +{ +public: + enum ItemType { DefaultType, UserType = 1000 }; + + /** + * Creates a KToolTipItem with @p text and no icon. + */ + explicit KToolTipItem(const QString &text, int type = DefaultType); + + /** + * Creates a KToolTipItem with an @p icon and @p text. + */ + KToolTipItem(const QIcon &icon, const QString &text, int type = DefaultType); + + /** + * Destroys the KToolTipItem. + */ + virtual ~KToolTipItem(); + + /** + * Returns the item type. + */ + int type() const; + + QString text() const; + QIcon icon() const; + + virtual QVariant data(int role) const; + virtual void setData(int role, const QVariant &data); + +private: + KToolTipItemPrivate * const d; +}; + + +class KStyleOptionToolTip +{ +public: + KStyleOptionToolTip(); + enum Corner { TopLeftCorner, TopRightCorner, BottomLeftCorner, BottomRightCorner, NoCorner }; + + Qt::LayoutDirection direction; + QFontMetrics fontMetrics; + QPalette palette; + QRect rect; + QStyle::State state; + QFont font; + QSize decorationSize; + Corner activeCorner; +}; + +/** + * KToolTipDelegate is responsible for providing the size hint and + * painting the tooltips. + */ +class KToolTipDelegate : public QObject +{ + Q_OBJECT +public: + KToolTipDelegate(); + virtual ~KToolTipDelegate(); + + virtual QSize sizeHint(const KStyleOptionToolTip *option, const KToolTipItem *item) const; + + /** + * If haveAlphaChannel() returns true, the paint device will be filled with + * Qt::transparent when this function is called, otherwise the content is + * undefined. + */ + virtual void paint(QPainter *painter, const KStyleOptionToolTip *option, + const KToolTipItem *item) const; + + /** + * Reimplement this function to specify the region of the tooltip + * that accepts input. Any mouse events that occur outside this + * region will be sent to the widget below the tooltip. + * + * The default implementation returns a region containing the + * bounding rect of the tooltip. + * + * This function will only be called if haveAlphaChannel() + * returns true. + */ + virtual QRegion inputShape(const KStyleOptionToolTip *option) const; + + /** + * Reimplement this function to specify a shape mask for the tooltip. + * + * The default implementation returns a region containing the + * bounding rect of the tooltip. + * + * This function will only be called if haveAlphaChannel() + * returns false. + */ + virtual QRegion shapeMask(const KStyleOptionToolTip *option) const; + +protected: + /** + * Returns true if the tooltip has an alpha channel, and false + * otherwise. + * + * Implementors should assume that this condition may change at + * any time during the runtime of the application, as compositing + * can be enabled or disabled in the window manager. + */ + bool haveAlphaChannel() const; + +#if 0 +private Q_SLOTS: + /** + * Schedules a repaint of the tooltip item. + * This slot can be connected to a timer to animate the tooltip. + */ + void update(const KToolTipItem *item); +#endif +}; + + +/** + * KToolTip provides customizable tooltips that can have animations as well as an alpha + * channel, allowing for dynamic transparency effects. + * + * ARGB tooltips work on X11 even when the application isn't using the ARGB visual. + */ +namespace KToolTip +{ + void showText(const QPoint &pos, const QString &text, QWidget *widget, const QRect &rect); + void showText(const QPoint &pos, const QString &text, QWidget *widget = 0); + + /** + * Shows the tip @p item at the global position indicated by @p pos. + * + * Ownership of the item is transferred to KToolTip. The item will be deleted + * automatically when it is hidden. + * + * The tip is shown immediately when this function is called. + */ + void showTip(const QPoint &pos, KToolTipItem *item); + void hideTip(); + + void setToolTipDelegate(KToolTipDelegate *delegate); +} + +#endif diff --git a/src/tooltips/ktooltip_p.h b/src/tooltips/ktooltip_p.h new file mode 100644 index 000000000..332df4854 --- /dev/null +++ b/src/tooltips/ktooltip_p.h @@ -0,0 +1,67 @@ +/*************************************************************************** + * Copyright (C) 2008 by Fredrik Höglund * + * * + * 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 of the License, 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. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#ifndef KTOOLTIP_P_H +#define KTOOLTIP_P_H + +class KAbstractToolTipLabel; +class KStyleOptionToolTip; +class KToolTipDelegate; + +class KToolTipManager +{ +public: + ~KToolTipManager(); + + static KToolTipManager *instance() { + if (!s_instance) + s_instance = new KToolTipManager(); + + return s_instance; + } + + void showTip(const QPoint &pos, KToolTipItem *item); + void hideTip(); + + void initStyleOption(KStyleOptionToolTip *option) const; + bool haveAlphaChannel() const; + + void setDelegate(KToolTipDelegate *delegate); + KToolTipDelegate *delegate() const; + + void update(); + +private: + KToolTipManager(); + + KAbstractToolTipLabel *label; + KToolTipItem *currentItem; + KToolTipDelegate *m_delegate; + + QPoint m_tooltipPos; + +#ifdef Q_WS_X11 + bool haveArgbVisual; + Atom net_wm_cm_s0; +#endif + + static KToolTipManager *s_instance; +}; + +#endif diff --git a/src/tooltips/tooltipmanager.cpp b/src/tooltips/tooltipmanager.cpp new file mode 100644 index 000000000..36a008f33 --- /dev/null +++ b/src/tooltips/tooltipmanager.cpp @@ -0,0 +1,307 @@ +/******************************************************************************* + * Copyright (C) 2008 by Konstantin Heil * + * * + * 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 of the License, 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. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + *******************************************************************************/ + +#include "tooltipmanager.h" + +#include "dolphintooltip.h" +#include "dolphinmodel.h" +#include "dolphinsortfilterproxymodel.h" + +#include +#include +#include + +#include +#include +#include +#include +#include + +const int ICON_WIDTH = 128; +const int ICON_HEIGHT = 128; +const int PREVIEW_DELAY = 250; + +K_GLOBAL_STATIC(DolphinBalloonTooltipDelegate, g_delegate) + +ToolTipManager::ToolTipManager(QAbstractItemView* parent, + DolphinSortFilterProxyModel* model) : + QObject(parent), + m_view(parent), + m_dolphinModel(0), + m_proxyModel(model), + m_timer(0), + m_previewTimer(0), + m_waitOnPreviewTimer(0), + m_item(), + m_itemRect(), + m_preview(false), + m_generatingPreview(false), + m_previewIsLate(false), + m_previewPass(0), + m_emptyRenderedKToolTipItem(0), + m_pix() +{ + KToolTip::setToolTipDelegate(g_delegate); + + m_dolphinModel = static_cast(m_proxyModel->sourceModel()); + connect(parent, SIGNAL(entered(const QModelIndex&)), + this, SLOT(requestToolTip(const QModelIndex&))); + connect(parent, SIGNAL(viewportEntered()), + this, SLOT(hideToolTip())); + + m_timer = new QTimer(this); + m_timer->setSingleShot(true); + connect(m_timer, SIGNAL(timeout()), + this, SLOT(prepareToolTip())); + + m_previewTimer = new QTimer(this); + m_previewTimer->setSingleShot(true); + connect(m_previewTimer, SIGNAL(timeout()), + this, SLOT(startPreviewJob())); + + m_waitOnPreviewTimer = new QTimer(this); + m_waitOnPreviewTimer->setSingleShot(true); + connect(m_waitOnPreviewTimer, SIGNAL(timeout()), + this, SLOT(prepareToolTip())); + + // When the mousewheel is used, the items don't get a hovered indication + // (Qt-issue #200665). To assure that the tooltip still gets hidden, + // the scrollbars are observed. + connect(parent->horizontalScrollBar(), SIGNAL(valueChanged(int)), + this, SLOT(hideTip())); + connect(parent->verticalScrollBar(), SIGNAL(valueChanged(int)), + this, SLOT(hideTip())); + + m_view->viewport()->installEventFilter(this); +} + +ToolTipManager::~ToolTipManager() +{ +} + +void ToolTipManager::hideTip() +{ + hideToolTip(); +} + +bool ToolTipManager::eventFilter(QObject* watched, QEvent* event) +{ + if ((watched == m_view->viewport()) && (event->type() == QEvent::Leave)) { + hideToolTip(); + } + + return QObject::eventFilter(watched, event); +} + +void ToolTipManager::requestToolTip(const QModelIndex& index) +{ + // only request a tooltip for the name column and when no selection or + // drag & drop operation is done (indicated by the left mouse button) + if ((index.column() == DolphinModel::Name) && !(QApplication::mouseButtons() & Qt::LeftButton)) { + m_waitOnPreviewTimer->stop(); + KToolTip::hideTip(); + + m_itemRect = m_view->visualRect(index); + const QPoint pos = m_view->viewport()->mapToGlobal(m_itemRect.topLeft()); + m_itemRect.moveTo(pos); + + const QModelIndex dirIndex = m_proxyModel->mapToSource(index); + m_item = m_dolphinModel->itemForIndex(dirIndex); + + // only start the previewJob when the mouse has been over this item for 200 milliseconds, + // this prevents a lot of useless preview jobs when passing rapidly over a lot of items + m_previewTimer->start(200); + m_preview = false; + m_previewIsLate = false; + m_previewPass = 0; + + m_timer->start(500); + } else { + hideToolTip(); + } +} + +void ToolTipManager::hideToolTip() +{ + m_timer->stop(); + m_previewTimer->stop(); + m_waitOnPreviewTimer->stop(); + m_previewIsLate = false; + KToolTip::hideTip(); +} + +void ToolTipManager::prepareToolTip() +{ + if (m_generatingPreview) { + if (m_previewPass == 1) { + // We waited 250msec and the preview is still not finished, + // so show the toolTip with a transparent image of maximal width. + // When the preview finishes, m_previewIsLate will cause + // a direct update of the tooltip, via m_emptyRenderedKToolTipItem. + QPixmap paddedImage(QSize(PREVIEW_WIDTH, 32)); + m_previewIsLate = true; + paddedImage.fill(Qt::transparent); + KToolTipItem* toolTip = new KToolTipItem(paddedImage, m_item.getToolTipText()); + m_emptyRenderedKToolTipItem = toolTip; // make toolTip accessible everywhere + showToolTip(toolTip); + } + + ++m_previewPass; + m_waitOnPreviewTimer->start(250); + } else { + // The preview generation has finished, find out under which circumstances. + if (m_preview && m_previewIsLate) { + // We got a preview, but it is late, the tooltip has already been shown. + // So update the tooltip directly. + if (m_emptyRenderedKToolTipItem != 0) { + m_emptyRenderedKToolTipItem->setData(Qt::DecorationRole, KIcon(m_pix)); + } + return; + } + + KIcon icon; + if (m_preview) { + // We got a preview. + icon = KIcon(m_pix); + } else { + // No preview, so use an icon. + // Force a 128x128 icon, a 256x256 one is far too big. + icon = KIcon(KIcon(m_item.iconName()).pixmap(ICON_WIDTH, ICON_HEIGHT)); + } + + KToolTipItem* toolTip = new KToolTipItem(icon, m_item.getToolTipText()); + showToolTip(toolTip); + } +} + +void ToolTipManager::showToolTip(KToolTipItem* tip) +{ + if (QApplication::mouseButtons() & Qt::LeftButton) { + delete tip; + tip = 0; + // m_emptyRenderedKToolTipItem is an alias for tip. + m_emptyRenderedKToolTipItem = 0; + return; + } + + KStyleOptionToolTip option; + // TODO: get option content from KToolTip or add KToolTip::sizeHint() method + option.direction = QApplication::layoutDirection(); + option.fontMetrics = QFontMetrics(QToolTip::font()); + option.activeCorner = KStyleOptionToolTip::TopLeftCorner; + option.palette = QToolTip::palette(); + option.font = QToolTip::font(); + option.rect = QRect(); + option.state = QStyle::State_None; + option.decorationSize = QSize(32, 32); + + QSize size; + if (m_previewIsLate) { + QPixmap paddedImage(QSize(PREVIEW_WIDTH, PREVIEW_HEIGHT)); + KToolTipItem* maxiTip = new KToolTipItem(paddedImage, m_item.getToolTipText()); + size = g_delegate->sizeHint(&option, maxiTip); + delete maxiTip; + maxiTip = 0; + } + else { + size = g_delegate->sizeHint(&option, tip); + } + const QRect desktop = QApplication::desktop()->screenGeometry(m_itemRect.bottomRight()); + + // m_itemRect defines the area of the item, where the tooltip should be + // shown. Per default the tooltip is shown in the bottom right corner. + // If the tooltip content exceeds the desktop borders, it must be assured that: + // - the content is fully visible + // - the content is not drawn inside m_itemRect + const bool hasRoomToLeft = (m_itemRect.left() - size.width() >= desktop.left()); + const bool hasRoomToRight = (m_itemRect.right() + size.width() <= desktop.right()); + const bool hasRoomAbove = (m_itemRect.top() - size.height() >= desktop.top()); + const bool hasRoomBelow = (m_itemRect.bottom() + size.height() <= desktop.bottom()); + if (!hasRoomAbove && !hasRoomBelow && !hasRoomToLeft && !hasRoomToRight) { + delete tip; + tip = 0; + return; + } + + int x = 0; + int y = 0; + if (hasRoomBelow || hasRoomAbove) { + x = QCursor::pos().x() + 16; // TODO: use mouse pointer width instead of the magic value of 16 + if (x + size.width() >= desktop.right()) { + x = desktop.right() - size.width(); + } + y = hasRoomBelow ? m_itemRect.bottom() : m_itemRect.top() - size.height(); + } else { + Q_ASSERT(hasRoomToLeft || hasRoomToRight); + x = hasRoomToRight ? m_itemRect.right() : m_itemRect.left() - size.width(); + + // Put the tooltip at the bottom of the screen. The x-coordinate has already + // been adjusted, so that no overlapping with m_itemRect occurs. + y = desktop.bottom() - size.height(); + } + + KToolTip::showTip(QPoint(x, y), tip); +} + + + +void ToolTipManager::startPreviewJob() +{ + m_generatingPreview = true; + KIO::PreviewJob* job = KIO::filePreview(KFileItemList() << m_item, + PREVIEW_WIDTH, + PREVIEW_HEIGHT); + job->setIgnoreMaximumSize(true); + + connect(job, SIGNAL(gotPreview(const KFileItem&, const QPixmap&)), + this, SLOT(setPreviewPix(const KFileItem&, const QPixmap&))); + connect(job, SIGNAL(failed(const KFileItem&)), + this, SLOT(previewFailed(const KFileItem&))); +} + + +void ToolTipManager::setPreviewPix(const KFileItem& item, + const QPixmap& pixmap) +{ + if (m_item.url() != item.url()) { + m_generatingPreview = false; + return; + } + + if (m_previewIsLate) { + // always use the maximal width + QPixmap paddedImage(QSize(PREVIEW_WIDTH, pixmap.height())); + paddedImage.fill(Qt::transparent); + QPainter painter(&paddedImage); + painter.drawPixmap((PREVIEW_WIDTH - pixmap.width()) / 2, 0, pixmap); + m_pix = paddedImage; + } else { + m_pix = pixmap; + } + m_preview = true; + m_generatingPreview = false; +} + +void ToolTipManager::previewFailed(const KFileItem& item) +{ + Q_UNUSED(item); + m_generatingPreview = false; +} + +#include "tooltipmanager.moc" diff --git a/src/tooltips/tooltipmanager.h b/src/tooltips/tooltipmanager.h new file mode 100644 index 000000000..96df4819e --- /dev/null +++ b/src/tooltips/tooltipmanager.h @@ -0,0 +1,91 @@ +/******************************************************************************* + * Copyright (C) 2008 by Konstantin Heil * + * * + * 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 of the License, 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. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + *******************************************************************************/ + +#ifndef TOOLTIPMANAGER_H +#define TOOLTIPMANAGER_H + +#include +#include + +#include + +class DolphinModel; +class DolphinSortFilterProxyModel; +class QAbstractItemView; +class QModelIndex; +class QTimer; +class KToolTipItem; + +/** + * @brief Manages the tooltips for an item view. + * + * When hovering an item, a tooltip is shown after + * a short timeout. The tooltip is hidden again when the + * viewport is hovered or the item view has been left. + */ +class ToolTipManager : public QObject +{ + Q_OBJECT + +public: + explicit ToolTipManager(QAbstractItemView* parent, + DolphinSortFilterProxyModel* model); + virtual ~ToolTipManager(); + +public slots: + /** + * Hides the currently shown tooltip. Invoking this method is + * only needed when the tooltip should be hidden although + * an item is hovered. + */ + void hideTip(); + +protected: + virtual bool eventFilter(QObject* watched, QEvent* event); + +private slots: + void requestToolTip(const QModelIndex& index); + void hideToolTip(); + void prepareToolTip(); + void startPreviewJob(); + void setPreviewPix(const KFileItem& item, const QPixmap& pix); + void previewFailed(const KFileItem& item); + +private: + void showToolTip(KToolTipItem* tip); + + QAbstractItemView* m_view; + DolphinModel* m_dolphinModel; + DolphinSortFilterProxyModel* m_proxyModel; + + QTimer* m_timer; + QTimer* m_previewTimer; + QTimer* m_waitOnPreviewTimer; + KFileItem m_item; + QRect m_itemRect; + bool m_preview; + bool m_generatingPreview; + bool m_previewIsLate; + int m_previewPass; + KToolTipItem* m_emptyRenderedKToolTipItem; + QPixmap m_pix; + +}; + +#endif diff --git a/src/treeviewcontextmenu.cpp b/src/treeviewcontextmenu.cpp deleted file mode 100644 index 9e8638002..000000000 --- a/src/treeviewcontextmenu.cpp +++ /dev/null @@ -1,194 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2006 by Peter Penz (peter.penz@gmx.at) and * - * Cvetoslav Ludmiloff * - * * - * 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 of the License, 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. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#include "treeviewcontextmenu.h" - -#include "dolphin_folderspanelsettings.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "treeviewsidebarpage.h" - -#include -#include - -TreeViewContextMenu::TreeViewContextMenu(TreeViewSidebarPage* parent, - const KFileItem& fileInfo) : - QObject(parent), - m_parent(parent), - m_fileInfo(fileInfo) -{ -} - -TreeViewContextMenu::~TreeViewContextMenu() -{ -} - -void TreeViewContextMenu::open() -{ - KMenu* popup = new KMenu(m_parent); - - if (!m_fileInfo.isNull()) { - KonqFileItemCapabilities capabilities(KFileItemList() << m_fileInfo); - - // insert 'Cut', 'Copy' and 'Paste' - QAction* cutAction = new QAction(KIcon("edit-cut"), i18nc("@action:inmenu", "Cut"), this); - cutAction->setEnabled(capabilities.supportsMoving()); - connect(cutAction, SIGNAL(triggered()), this, SLOT(cut())); - - QAction* copyAction = new QAction(KIcon("edit-copy"), i18nc("@action:inmenu", "Copy"), this); - connect(copyAction, SIGNAL(triggered()), this, SLOT(copy())); - - QAction* pasteAction = new QAction(KIcon("edit-paste"), i18nc("@action:inmenu", "Paste"), this); - const QMimeData* mimeData = QApplication::clipboard()->mimeData(); - const KUrl::List pasteData = KUrl::List::fromMimeData(mimeData); - connect(pasteAction, SIGNAL(triggered()), this, SLOT(paste())); - pasteAction->setEnabled(!pasteData.isEmpty() && capabilities.supportsWriting()); - - popup->addAction(cutAction); - popup->addAction(copyAction); - popup->addAction(pasteAction); - popup->addSeparator(); - - // insert 'Rename' - QAction* renameAction = new QAction(i18nc("@action:inmenu", "Rename..."), this); - renameAction->setEnabled(capabilities.supportsMoving()); - connect(renameAction, SIGNAL(triggered()), this, SLOT(rename())); - popup->addAction(renameAction); - - // insert 'Move to Trash' and (optionally) 'Delete' - KSharedConfig::Ptr globalConfig = KSharedConfig::openConfig("kdeglobals", KConfig::IncludeGlobals); - KConfigGroup configGroup(globalConfig, "KDE"); - bool showDeleteCommand = configGroup.readEntry("ShowDeleteCommand", false); - - const KUrl& url = m_fileInfo.url(); - if (url.isLocalFile()) { - QAction* moveToTrashAction = new QAction(KIcon("user-trash"), - i18nc("@action:inmenu", "Move To Trash"), this); - const bool enableMoveToTrash = capabilities.isLocal() && capabilities.supportsMoving(); - moveToTrashAction->setEnabled(enableMoveToTrash); - connect(moveToTrashAction, SIGNAL(triggered()), this, SLOT(moveToTrash())); - popup->addAction(moveToTrashAction); - } else { - showDeleteCommand = true; - } - - if (showDeleteCommand) { - QAction* deleteAction = new QAction(KIcon("edit-delete"), i18nc("@action:inmenu", "Delete"), this); - deleteAction->setEnabled(capabilities.supportsDeleting()); - connect(deleteAction, SIGNAL(triggered()), this, SLOT(deleteItem())); - popup->addAction(deleteAction); - } - - popup->addSeparator(); - - // insert 'Properties' entry - QAction* propertiesAction = new QAction(i18nc("@action:inmenu", "Properties"), this); - connect(propertiesAction, SIGNAL(triggered()), this, SLOT(showProperties())); - popup->addAction(propertiesAction); - - popup->addSeparator(); - } - - QAction* showHiddenFilesAction = new QAction(i18nc("@action:inmenu", "Show Hidden Files"), this); - showHiddenFilesAction->setCheckable(true); - showHiddenFilesAction->setChecked(FoldersPanelSettings::showHiddenFiles()); - popup->addAction(showHiddenFilesAction); - - connect(showHiddenFilesAction, SIGNAL(toggled(bool)), this, SLOT(setShowHiddenFiles(bool))); - - popup->exec(QCursor::pos()); - popup->deleteLater(); -} - -void TreeViewContextMenu::populateMimeData(QMimeData* mimeData, bool cut) -{ - KUrl::List kdeUrls; - kdeUrls.append(m_fileInfo.url()); - KUrl::List mostLocalUrls; - bool dummy; - mostLocalUrls.append(m_fileInfo.mostLocalUrl(dummy)); - KonqMimeData::populateMimeData(mimeData, kdeUrls, mostLocalUrls, cut); -} - -void TreeViewContextMenu::cut() -{ - QMimeData* mimeData = new QMimeData(); - populateMimeData(mimeData, true); - QApplication::clipboard()->setMimeData(mimeData); -} - -void TreeViewContextMenu::copy() -{ - QMimeData* mimeData = new QMimeData(); - populateMimeData(mimeData, false); - QApplication::clipboard()->setMimeData(mimeData); -} - -void TreeViewContextMenu::paste() -{ - QClipboard* clipboard = QApplication::clipboard(); - const QMimeData* mimeData = clipboard->mimeData(); - - const KUrl::List source = KUrl::List::fromMimeData(mimeData); - const KUrl& dest = m_fileInfo.url(); - if (KonqMimeData::decodeIsCutSelection(mimeData)) { - KonqOperations::copy(m_parent, KonqOperations::MOVE, source, dest); - clipboard->clear(); - } else { - KonqOperations::copy(m_parent, KonqOperations::COPY, source, dest); - } -} - -void TreeViewContextMenu::rename() -{ - m_parent->rename(m_fileInfo); -} - -void TreeViewContextMenu::moveToTrash() -{ - KonqOperations::del(m_parent, KonqOperations::TRASH, m_fileInfo.url()); -} - -void TreeViewContextMenu::deleteItem() -{ - KonqOperations::del(m_parent, KonqOperations::DEL, m_fileInfo.url()); -} - -void TreeViewContextMenu::showProperties() -{ - KPropertiesDialog dialog(m_fileInfo.url(), m_parent); - dialog.exec(); -} - -void TreeViewContextMenu::setShowHiddenFiles(bool show) -{ - m_parent->setShowHiddenFiles(show); -} - -#include "treeviewcontextmenu.moc" diff --git a/src/treeviewcontextmenu.h b/src/treeviewcontextmenu.h deleted file mode 100644 index 20a603573..000000000 --- a/src/treeviewcontextmenu.h +++ /dev/null @@ -1,88 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2006 by Peter Penz * - * * - * 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 of the License, 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. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#ifndef TREEVIEWCONTEXTMENU_H -#define TREEVIEWCONTEXTMENU_H - -#include -#include - -class TreeViewSidebarPage; - -/** - * @brief Represents the context menu which appears when doing a right - * click on an item of the treeview. - */ -class TreeViewContextMenu : public QObject -{ - Q_OBJECT - -public: - /** - * @parent Pointer to the treeview sidebar page the context menu - * belongs to. - * @fileInfo Pointer to the file item the context menu - * is applied. If 0 is passed, the context menu - * is above the viewport. - */ - TreeViewContextMenu(TreeViewSidebarPage* parent, - const KFileItem& fileInfo); - - virtual ~TreeViewContextMenu(); - - /** Opens the context menu modal. */ - void open(); - -private slots: - /** Cuts the item m_fileInfo. */ - void cut(); - - /** Copies the item m_fileInfo. */ - void copy(); - - /** Paste the clipboard to m_fileInfo. */ - void paste(); - - /** Renames the item m_fileInfo. */ - void rename(); - - /** Moves the item m_fileInfo to the trash. */ - void moveToTrash(); - - /** Deletes the item m_fileInfo. */ - void deleteItem(); - - /** Shows the properties of the item m_fileInfo. */ - void showProperties(); - - /** - * Sets the 'Show Hidden Files' setting for the - * folders panel to \a show. - */ - void setShowHiddenFiles(bool show); - -private: - void populateMimeData(QMimeData* mimeData, bool cut); - -private: - TreeViewSidebarPage* m_parent; - KFileItem m_fileInfo; -}; - -#endif diff --git a/src/treeviewsidebarpage.cpp b/src/treeviewsidebarpage.cpp deleted file mode 100644 index d8387aea2..000000000 --- a/src/treeviewsidebarpage.cpp +++ /dev/null @@ -1,279 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2006 by Peter Penz * - * * - * 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 of the License, 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. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#include "treeviewsidebarpage.h" - -#include "dolphinmodel.h" -#include "dolphinsortfilterproxymodel.h" -#include "dolphinview.h" -#include "dolphinsettings.h" -#include "dolphin_folderspanelsettings.h" -#include "dolphin_generalsettings.h" -#include "draganddrophelper.h" -#include "folderexpander.h" -#include "renamedialog.h" -#include "sidebartreeview.h" -#include "treeviewcontextmenu.h" - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -TreeViewSidebarPage::TreeViewSidebarPage(QWidget* parent) : - SidebarPage(parent), - m_setLeafVisible(false), - m_mouseButtons(Qt::NoButton), - m_dirLister(0), - m_dolphinModel(0), - m_proxyModel(0), - m_treeView(0), - m_leafDir() -{ - setLayoutDirection(Qt::LeftToRight); -} - -TreeViewSidebarPage::~TreeViewSidebarPage() -{ - FoldersPanelSettings::self()->writeConfig(); - - delete m_proxyModel; - m_proxyModel = 0; - delete m_dolphinModel; - m_dolphinModel = 0; - m_dirLister = 0; // deleted by m_dolphinModel -} - -QSize TreeViewSidebarPage::sizeHint() const -{ - return QSize(200, 400); -} - -void TreeViewSidebarPage::setShowHiddenFiles(bool show) -{ - FoldersPanelSettings::setShowHiddenFiles(show); - if (m_dirLister != 0) { - m_dirLister->setShowingDotFiles(show); - m_dirLister->openUrl(m_dirLister->url(), KDirLister::Reload); - } -} - -bool TreeViewSidebarPage::showHiddenFiles() const -{ - return FoldersPanelSettings::showHiddenFiles(); -} - -void TreeViewSidebarPage::rename(const KFileItem& item) -{ - if (DolphinSettings::instance().generalSettings()->renameInline()) { - const QModelIndex dirIndex = m_dolphinModel->indexForItem(item); - const QModelIndex proxyIndex = m_proxyModel->mapFromSource(dirIndex); - m_treeView->edit(proxyIndex); - } else { - KFileItemList items; - items.append(item); - RenameDialog dialog(this, items); - if (dialog.exec() == QDialog::Accepted) { - const QString& newName = dialog.newName(); - if (!newName.isEmpty()) { - KUrl newUrl = item.url(); - newUrl.setFileName(newName); - KonqOperations::rename(this, item.url(), newUrl); - } - } - } -} - -void TreeViewSidebarPage::setUrl(const KUrl& url) -{ - if (!url.isValid() || (url == SidebarPage::url())) { - return; - } - - SidebarPage::setUrl(url); - if (m_dirLister != 0) { - m_setLeafVisible = true; - loadTree(url); - } -} - -void TreeViewSidebarPage::showEvent(QShowEvent* event) -{ - if (event->spontaneous()) { - SidebarPage::showEvent(event); - return; - } - - if (m_dirLister == 0) { - // Postpone the creating of the dir lister to the first show event. - // This assures that no performance and memory overhead is given when the TreeView is not - // used at all (see TreeViewSidebarPage::setUrl()). - m_dirLister = new KDirLister(); - m_dirLister->setDirOnlyMode(true); - m_dirLister->setAutoUpdate(true); - m_dirLister->setMainWindow(window()); - m_dirLister->setDelayedMimeTypes(true); - m_dirLister->setAutoErrorHandlingEnabled(false, this); - m_dirLister->setShowingDotFiles(FoldersPanelSettings::showHiddenFiles()); - - Q_ASSERT(m_dolphinModel == 0); - m_dolphinModel = new DolphinModel(this); - m_dolphinModel->setDirLister(m_dirLister); - m_dolphinModel->setDropsAllowed(DolphinModel::DropOnDirectory); - connect(m_dolphinModel, SIGNAL(expand(const QModelIndex&)), - this, SLOT(expandToDir(const QModelIndex&))); - - Q_ASSERT(m_proxyModel == 0); - m_proxyModel = new DolphinSortFilterProxyModel(this); - m_proxyModel->setSourceModel(m_dolphinModel); - - Q_ASSERT(m_treeView == 0); - m_treeView = new SidebarTreeView(this); - m_treeView->setModel(m_proxyModel); - m_proxyModel->setSorting(DolphinView::SortByName); - m_proxyModel->setSortOrder(Qt::AscendingOrder); - - new FolderExpander(m_treeView, m_proxyModel); - - connect(m_treeView, SIGNAL(clicked(const QModelIndex&)), - this, SLOT(updateActiveView(const QModelIndex&))); - connect(m_treeView, SIGNAL(urlsDropped(const QModelIndex&, QDropEvent*)), - this, SLOT(dropUrls(const QModelIndex&, QDropEvent*))); - connect(m_treeView, SIGNAL(pressed(const QModelIndex&)), - this, SLOT(updateMouseButtons())); - - QVBoxLayout* layout = new QVBoxLayout(this); - layout->setMargin(0); - layout->addWidget(m_treeView); - } - - loadTree(url()); - SidebarPage::showEvent(event); -} - -void TreeViewSidebarPage::contextMenuEvent(QContextMenuEvent* event) -{ - SidebarPage::contextMenuEvent(event); - - KFileItem item; - const QModelIndex index = m_treeView->indexAt(event->pos()); - if (index.isValid()) { - const QModelIndex dolphinModelIndex = m_proxyModel->mapToSource(index); - item = m_dolphinModel->itemForIndex(dolphinModelIndex); - emit changeSelection(KFileItemList()); - } - - TreeViewContextMenu contextMenu(this, item); - contextMenu.open(); -} - -void TreeViewSidebarPage::updateActiveView(const QModelIndex& index) -{ - const QModelIndex dirIndex = m_proxyModel->mapToSource(index); - const KFileItem item = m_dolphinModel->itemForIndex(dirIndex); - if (!item.isNull()) { - emit changeUrl(item.url(), m_mouseButtons); - } -} - -void TreeViewSidebarPage::dropUrls(const QModelIndex& index, QDropEvent* event) -{ - if (index.isValid()) { - const QModelIndex dirIndex = m_proxyModel->mapToSource(index); - KFileItem item = m_dolphinModel->itemForIndex(dirIndex); - Q_ASSERT(!item.isNull()); - if (item.isDir()) { - DragAndDropHelper::instance().dropUrls(item, item.url(), event, this); - } - } -} - -void TreeViewSidebarPage::expandToDir(const QModelIndex& index) -{ - m_treeView->setExpanded(index, true); - selectLeafDirectory(); - m_treeView->resizeColumnToContents(DolphinModel::Name); -} - -void TreeViewSidebarPage::scrollToLeaf() -{ - const QModelIndex dirIndex = m_dolphinModel->indexForUrl(m_leafDir); - const QModelIndex proxyIndex = m_proxyModel->mapFromSource(dirIndex); - if (proxyIndex.isValid()) { - m_treeView->scrollTo(proxyIndex); - } -} - -void TreeViewSidebarPage::updateMouseButtons() -{ - m_mouseButtons = QApplication::mouseButtons(); -} - -void TreeViewSidebarPage::loadTree(const KUrl& url) -{ - Q_ASSERT(m_dirLister != 0); - m_leafDir = url; - - KUrl baseUrl; - if (url.isLocalFile()) { - // use the root directory as base for local URLs (#150941) - baseUrl = QDir::rootPath(); - } else { - // clear the path for non-local URLs and use it as base - baseUrl = url; - baseUrl.setPath(QString('/')); - } - - if (m_dirLister->url() != baseUrl) { - m_dirLister->stop(); - m_dirLister->openUrl(baseUrl, KDirLister::Reload); - } - m_dolphinModel->expandToUrl(m_leafDir); -} - -void TreeViewSidebarPage::selectLeafDirectory() -{ - const QModelIndex dirIndex = m_dolphinModel->indexForUrl(m_leafDir); - const QModelIndex proxyIndex = m_proxyModel->mapFromSource(dirIndex); - if (!proxyIndex.isValid()) { - return; - } - - if (m_setLeafVisible) { - // Invoke m_treeView->scrollTo(proxyIndex) asynchronously by - // scrollToLeaf(). This assures that the scrolling is done after - // the horizontal scrollbar gets visible (otherwise the scrollbar - // might hide the leaf). - QTimer::singleShot(100, this, SLOT(scrollToLeaf())); - m_setLeafVisible = false; - } - - QItemSelectionModel* selModel = m_treeView->selectionModel(); - selModel->setCurrentIndex(proxyIndex, QItemSelectionModel::ClearAndSelect); -} - -#include "treeviewsidebarpage.moc" diff --git a/src/treeviewsidebarpage.h b/src/treeviewsidebarpage.h deleted file mode 100644 index 84a9386ec..000000000 --- a/src/treeviewsidebarpage.h +++ /dev/null @@ -1,135 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2006 by Peter Penz * - * * - * 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 of the License, 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. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#ifndef TREEVIEWSIDEBARPAGE_H -#define TREEVIEWSIDEBARPAGE_H - -#include -#include - -class KDirLister; -class DolphinModel; - -class DolphinSortFilterProxyModel; -class SidebarTreeView; -class QModelIndex; - -/** - * @brief Shows a tree view of the directories starting from - * the currently selected place. - * - * The tree view is always synchronized with the currently active view - * from the main window. - */ -class TreeViewSidebarPage : public SidebarPage -{ - Q_OBJECT - -public: - TreeViewSidebarPage(QWidget* parent = 0); - virtual ~TreeViewSidebarPage(); - - /** @see QWidget::sizeHint() */ - virtual QSize sizeHint() const; - - void setShowHiddenFiles(bool show); - bool showHiddenFiles() const; - - void rename(const KFileItem& item); - -signals: - /** - * Is emitted if the an URL change is requested. - */ - void changeUrl(const KUrl& url, Qt::MouseButtons buttons); - - /** - * This signal is emitted when the sidebar requests a change in the - * current selection. The file-management view recieving this signal is - * not required to select all listed files, limiting the selection to - * e.g. the current folder. The new selection will be reported via the - * setSelection slot. - */ - void changeSelection(const KFileItemList& selection); - -public slots: - /** - * Changes the current selection inside the tree to \a url. - */ - virtual void setUrl(const KUrl& url); - -protected: - /** @see QWidget::showEvent() */ - virtual void showEvent(QShowEvent* event); - - /** @see QWidget::contextMenuEvent() */ - virtual void contextMenuEvent(QContextMenuEvent* event); - -private slots: - /** - * Updates the active view to the URL - * which is given by the item with the index \a index. - */ - void updateActiveView(const QModelIndex& index); - - /** - * Is emitted if URLs have been dropped - * to the index \a index. - */ - void dropUrls(const QModelIndex& index, QDropEvent* event); - - /** - * Expands the treeview to show the directory - * specified by \a index. - */ - void expandToDir(const QModelIndex& index); - - /** - * Assures that the leaf folder gets visible. - */ - void scrollToLeaf(); - - void updateMouseButtons(); - -private: - /** - * Initializes the base URL of the tree and expands all - * directories until \a url. - * @param url URL of the leaf directory that should get expanded. - */ - void loadTree(const KUrl& url); - - /** - * Selects the current leaf directory m_leafDir and assures - * that the directory is visible if the leaf has been set by - * TreeViewSidebarPage::setUrl(). - */ - void selectLeafDirectory(); - -private: - bool m_setLeafVisible; - Qt::MouseButtons m_mouseButtons; - KDirLister* m_dirLister; - DolphinModel* m_dolphinModel; - DolphinSortFilterProxyModel* m_proxyModel; - SidebarTreeView* m_treeView; - KUrl m_leafDir; -}; - -#endif // TREEVIEWSIDEBARPAGE_H diff --git a/src/viewproperties.cpp b/src/viewproperties.cpp index 9b173d1c4..62898e670 100644 --- a/src/viewproperties.cpp +++ b/src/viewproperties.cpp @@ -20,7 +20,7 @@ #include "viewproperties.h" -#include "dolphinsettings.h" +#include "settings/dolphinsettings.h" #include "dolphin_directoryviewpropertysettings.h" #include "dolphin_generalsettings.h" diff --git a/src/viewpropertiesdialog.cpp b/src/viewpropertiesdialog.cpp deleted file mode 100644 index 9302ba138..000000000 --- a/src/viewpropertiesdialog.cpp +++ /dev/null @@ -1,405 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2006 by Peter Penz * - * peter.penz@gmx.at * - * * - * 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 of the License, 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. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#include "viewpropertiesdialog.h" - -#include "additionalinfodialog.h" -#include "dolphinview.h" -#include "dolphinsettings.h" -#include "dolphinsortfilterproxymodel.h" -#include "dolphin_generalsettings.h" -#include "dolphin_iconsmodesettings.h" -#include "viewproperties.h" -#include "viewpropsprogressinfo.h" - -#include -#ifdef HAVE_NEPOMUK -#include -#endif - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -ViewPropertiesDialog::ViewPropertiesDialog(DolphinView* dolphinView) : - KDialog(dolphinView), - m_isDirty(false), - m_dolphinView(dolphinView), - m_viewProps(0), - m_viewMode(0), - m_sortOrder(0), - m_sorting(0), - m_showPreview(0), - m_showInGroups(0), - m_showHiddenFiles(0), - m_additionalInfo(0), - m_applyToCurrentFolder(0), - m_applyToSubFolders(0), - m_applyToAllFolders(0), - m_useAsDefault(0) -{ - Q_ASSERT(dolphinView != 0); - const bool useGlobalViewProps = DolphinSettings::instance().generalSettings()->globalViewProps(); - - setCaption(i18nc("@title:window", "View Properties")); - setButtons(KDialog::Ok | KDialog::Cancel | KDialog::Apply); - - const KUrl& url = dolphinView->url(); - m_viewProps = new ViewProperties(url); - m_viewProps->setAutoSaveEnabled(false); - - QWidget* main = new QWidget(); - QVBoxLayout* topLayout = new QVBoxLayout(); - - // create 'Properties' group containing view mode, sorting, sort order and show hidden files - QWidget* propsBox = main; - if (!useGlobalViewProps) { - propsBox = new QGroupBox(i18nc("@title:group", "Properties"), main); - } - - QWidget* propsGrid = new QWidget(); - - QLabel* viewModeLabel = new QLabel(i18nc("@label:listbox", "View mode:"), propsGrid); - m_viewMode = new KComboBox(propsGrid); - m_viewMode->addItem(KIcon("view-list-icons"), i18nc("@item:inlistbox", "Icons")); - m_viewMode->addItem(KIcon("view-list-details"), i18nc("@item:inlistbox", "Details")); - m_viewMode->addItem(KIcon("view-file-columns"), i18nc("@item:inlistbox", "Column")); - - QLabel* sortingLabel = new QLabel(i18nc("@label:listbox", "Sorting:"), propsGrid); - QWidget* sortingBox = new QWidget(propsGrid); - - m_sortOrder = new KComboBox(sortingBox); - m_sortOrder->addItem(i18nc("@item:inlistbox Sort", "Ascending")); - m_sortOrder->addItem(i18nc("@item:inlistbox Sort", "Descending")); - - m_sorting = new KComboBox(sortingBox); - m_sorting->addItem(i18nc("@item:inlistbox Sort", "By Name")); - m_sorting->addItem(i18nc("@item:inlistbox Sort", "By Size")); - m_sorting->addItem(i18nc("@item:inlistbox Sort", "By Date")); - m_sorting->addItem(i18nc("@item:inlistbox Sort", "By Permissions")); - m_sorting->addItem(i18nc("@item:inlistbox Sort", "By Owner")); - m_sorting->addItem(i18nc("@item:inlistbox Sort", "By Group")); - m_sorting->addItem(i18nc("@item:inlistbox Sort", "By Type")); -#ifdef HAVE_NEPOMUK - // TODO: Hided "sort by rating" and "sort by tags" as without caching the performance - // is too slow currently (Nepomuk will support caching in future releases). - // - // if (!Nepomuk::ResourceManager::instance()->init()) { - // m_sorting->addItem(i18nc("@item:inlistbox Sort", "By Rating")); - // m_sorting->addItem(i18nc("@item:inlistbox Sort", "By Tags")); - // } -#endif - m_showPreview = new QCheckBox(i18nc("@option:check", "Show preview"), propsBox); - m_showInGroups = new QCheckBox(i18nc("@option:check", "Show in groups"), propsBox); - m_showHiddenFiles = new QCheckBox(i18nc("@option:check", "Show hidden files"), propsBox); - - m_additionalInfo = new QPushButton(i18nc("@action:button", "Additional Information"), propsBox); - - QHBoxLayout* sortingLayout = new QHBoxLayout(); - sortingLayout->setMargin(0); - sortingLayout->addWidget(m_sortOrder); - sortingLayout->addWidget(m_sorting); - sortingBox->setLayout(sortingLayout); - - QGridLayout* propsGridLayout = new QGridLayout(propsGrid); - propsGridLayout->addWidget(viewModeLabel, 0, 0, Qt::AlignRight); - propsGridLayout->addWidget(m_viewMode, 0, 1); - propsGridLayout->addWidget(sortingLabel, 1, 0, Qt::AlignRight); - propsGridLayout->addWidget(sortingBox, 1, 1); - - QVBoxLayout* propsBoxLayout = new QVBoxLayout(propsBox); - propsBoxLayout->addWidget(propsGrid); - propsBoxLayout->addWidget(m_showPreview); - propsBoxLayout->addWidget(m_showInGroups); - propsBoxLayout->addWidget(m_showHiddenFiles); - propsBoxLayout->addWidget(m_additionalInfo); - - topLayout->addWidget(propsBox); - - connect(m_viewMode, SIGNAL(activated(int)), - this, SLOT(slotViewModeChanged(int))); - connect(m_sorting, SIGNAL(activated(int)), - this, SLOT(slotSortingChanged(int))); - connect(m_sortOrder, SIGNAL(activated(int)), - this, SLOT(slotSortOrderChanged(int))); - connect(m_additionalInfo, SIGNAL(clicked()), - this, SLOT(configureAdditionalInfo())); - connect(m_showPreview, SIGNAL(clicked()), - this, SLOT(slotShowPreviewChanged())); - connect(m_showInGroups, SIGNAL(clicked()), - this, SLOT(slotCategorizedSortingChanged())); - connect(m_showHiddenFiles, SIGNAL(clicked()), - this, SLOT(slotShowHiddenFilesChanged())); - - connect(this, SIGNAL(okClicked()), this, SLOT(slotOk())); - connect(this, SIGNAL(applyClicked()), this, SLOT(slotApply())); - - // Only show the following settings if the view properties are remembered - // for each directory: - if (!useGlobalViewProps) { - // create 'Apply View Properties To' group - QGroupBox* applyBox = new QGroupBox(i18nc("@title:group", "Apply View Properties To"), main); - - m_applyToCurrentFolder = new QRadioButton(i18nc("@option:radio Apply View Properties To", - "Current folder"), applyBox); - m_applyToCurrentFolder->setChecked(true); - m_applyToSubFolders = new QRadioButton(i18nc("@option:radio Apply View Properties To", - "Current folder including all sub folders"), applyBox); - m_applyToAllFolders = new QRadioButton(i18nc("@option:radio Apply View Properties To", - "All folders"), applyBox); - - QButtonGroup* applyGroup = new QButtonGroup(this); - applyGroup->addButton(m_applyToCurrentFolder); - applyGroup->addButton(m_applyToSubFolders); - applyGroup->addButton(m_applyToAllFolders); - - QVBoxLayout* applyBoxLayout = new QVBoxLayout(applyBox); - applyBoxLayout->addWidget(m_applyToCurrentFolder); - applyBoxLayout->addWidget(m_applyToSubFolders); - applyBoxLayout->addWidget(m_applyToAllFolders); - - m_useAsDefault = new QCheckBox(i18nc("@option:check", "Use as default for new folders"), main); - - topLayout->addWidget(applyBox); - topLayout->addWidget(m_useAsDefault); - - connect(m_applyToCurrentFolder, SIGNAL(clicked()), - this, SLOT(markAsDirty())); - connect(m_applyToSubFolders, SIGNAL(clicked()), - this, SLOT(markAsDirty())); - connect(m_applyToAllFolders, SIGNAL(clicked()), - this, SLOT(markAsDirty())); - connect(m_useAsDefault, SIGNAL(clicked()), - this, SLOT(markAsDirty())); - } - - main->setLayout(topLayout); - setMainWidget(main); - - const KConfigGroup dialogConfig(KSharedConfig::openConfig("dolphinrc"), - "ViewPropertiesDialog"); - restoreDialogSize(dialogConfig); - - loadSettings(); -} - -ViewPropertiesDialog::~ViewPropertiesDialog() -{ - m_isDirty = false; - delete m_viewProps; - m_viewProps = 0; - - KConfigGroup dialogConfig(KSharedConfig::openConfig("dolphinrc"), - "ViewPropertiesDialog"); - saveDialogSize(dialogConfig, KConfigBase::Persistent); -} - -void ViewPropertiesDialog::slotOk() -{ - applyViewProperties(); - accept(); -} - -void ViewPropertiesDialog::slotApply() -{ - applyViewProperties(); -} - -void ViewPropertiesDialog::slotViewModeChanged(int index) -{ - m_viewProps->setViewMode(static_cast(index)); - m_isDirty = true; - - const DolphinView::Mode mode = m_viewProps->viewMode(); - m_showInGroups->setEnabled(mode == DolphinView::IconsView); - m_additionalInfo->setEnabled(mode != DolphinView::ColumnView); -} - -void ViewPropertiesDialog::slotSortingChanged(int index) -{ - const DolphinView::Sorting sorting = DolphinSortFilterProxyModel::sortingForColumn(index); - m_viewProps->setSorting(sorting); - m_isDirty = true; -} - -void ViewPropertiesDialog::slotSortOrderChanged(int index) -{ - const Qt::SortOrder sortOrder = (index == 0) ? Qt::AscendingOrder : Qt::DescendingOrder; - m_viewProps->setSortOrder(sortOrder); - m_isDirty = true; -} - -void ViewPropertiesDialog::slotCategorizedSortingChanged() -{ - m_viewProps->setCategorizedSorting(m_showInGroups->isChecked()); - m_isDirty = true; -} - -void ViewPropertiesDialog::slotShowPreviewChanged() -{ - const bool show = m_showPreview->isChecked(); - m_viewProps->setShowPreview(show); - m_isDirty = true; -} - -void ViewPropertiesDialog::slotShowHiddenFilesChanged() -{ - const bool show = m_showHiddenFiles->isChecked(); - m_viewProps->setShowHiddenFiles(show); - m_isDirty = true; -} - -void ViewPropertiesDialog::markAsDirty() -{ - m_isDirty = true; -} - -void ViewPropertiesDialog::configureAdditionalInfo() -{ - KFileItemDelegate::InformationList info = m_viewProps->additionalInfo(); - const bool useDefaultInfo = (m_viewProps->viewMode() == DolphinView::DetailsView) && - (info.isEmpty() || info.contains(KFileItemDelegate::NoInformation)); - if (useDefaultInfo) { - // Using the details view without any additional information (-> additional column) - // makes no sense and leads to a usability problem as no viewport area is available - // anymore. Hence as fallback provide at least a size and date column. - info.clear(); - info.append(KFileItemDelegate::Size); - info.append(KFileItemDelegate::ModificationTime); - m_viewProps->setAdditionalInfo(info); - } - - AdditionalInfoDialog dialog(this, info); - if (dialog.exec() == QDialog::Accepted) { - m_viewProps->setAdditionalInfo(dialog.additionalInfo()); - m_isDirty = true; - } -} - -void ViewPropertiesDialog::applyViewProperties() -{ - // if nothing changed in the dialog, we have nothing to apply - if (!m_isDirty) { - return; - } - - const bool applyToSubFolders = (m_applyToSubFolders != 0) && - m_applyToSubFolders->isChecked(); - if (applyToSubFolders) { - const QString text(i18nc("@info", "The view properties of all sub folders will be changed. Do you want to continue?")); - if (KMessageBox::questionYesNo(this, text) == KMessageBox::No) { - return; - } - - ViewPropsProgressInfo* info = new ViewPropsProgressInfo(m_dolphinView, - m_dolphinView->url(), - *m_viewProps); - info->setAttribute(Qt::WA_DeleteOnClose); - info->setWindowModality(Qt::NonModal); - info->show(); - } - - const bool applyToAllFolders = (m_applyToAllFolders != 0) && - m_applyToAllFolders->isChecked(); - - // If the user selected 'Apply To All Folders' the view properties implicitely - // are also used as default for new folders. - const bool useAsDefault = applyToAllFolders || - ((m_useAsDefault != 0) && m_useAsDefault->isChecked()); - if (useAsDefault) { - // For directories where no .directory file is available, the .directory - // file stored for the global view properties is used as fallback. To update - // this file we temporary turn on the global view properties mode. - GeneralSettings* settings = DolphinSettings::instance().generalSettings(); - Q_ASSERT(!settings->globalViewProps()); - - settings->setGlobalViewProps(true); - ViewProperties defaultProps(m_dolphinView->url()); - defaultProps.setDirProperties(*m_viewProps); - defaultProps.save(); - settings->setGlobalViewProps(false); - } - - if (applyToAllFolders) { - const QString text(i18nc("@info", "The view properties of all folders will be changed. Do you want to continue?")); - if (KMessageBox::questionYesNo(this, text) == KMessageBox::No) { - return; - } - - // Updating the global view properties time stamp in the general settings makes - // all existing viewproperties invalid, as they have a smaller time stamp. - GeneralSettings* settings = DolphinSettings::instance().generalSettings(); - settings->setViewPropsTimestamp(QDateTime::currentDateTime()); - } - - m_dolphinView->setMode(m_viewProps->viewMode()); - m_dolphinView->setSorting(m_viewProps->sorting()); - m_dolphinView->setSortOrder(m_viewProps->sortOrder()); - m_dolphinView->setCategorizedSorting(m_viewProps->categorizedSorting()); - m_dolphinView->setAdditionalInfo(m_viewProps->additionalInfo()); - m_dolphinView->setShowPreview(m_viewProps->showPreview()); - m_dolphinView->setShowHiddenFiles(m_viewProps->showHiddenFiles()); - - m_viewProps->save(); - - m_isDirty = false; -} - -void ViewPropertiesDialog::loadSettings() -{ - // load view mode - const int index = static_cast(m_viewProps->viewMode()); - m_viewMode->setCurrentIndex(index); - - // load sort order and sorting - const int sortOrderIndex = (m_viewProps->sortOrder() == Qt::AscendingOrder) ? 0 : 1; - m_sortOrder->setCurrentIndex(sortOrderIndex); - m_sorting->setCurrentIndex(m_viewProps->sorting()); - - const bool enabled = (index == DolphinView::DetailsView) || - (index == DolphinView::IconsView); - m_additionalInfo->setEnabled(enabled); - - // load show preview, show in groups and show hidden files settings - m_showPreview->setChecked(m_viewProps->showPreview()); - - m_showInGroups->setChecked(m_viewProps->categorizedSorting()); - m_showInGroups->setEnabled(index == DolphinView::IconsView); // only the icons view supports categorized sorting - - m_showHiddenFiles->setChecked(m_viewProps->showHiddenFiles()); -} - -#include "viewpropertiesdialog.moc" diff --git a/src/viewpropertiesdialog.h b/src/viewpropertiesdialog.h deleted file mode 100644 index 320f8f115..000000000 --- a/src/viewpropertiesdialog.h +++ /dev/null @@ -1,84 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2006 by Peter Penz * - * peter.penz@gmx.at * - * * - * 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 of the License, 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. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#ifndef VIEWPROPERTIESDIALOG_H -#define VIEWPROPERTIESDIALOG_H - -#include "libdolphin_export.h" - -#include - -class QCheckBox; -class KComboBox; -class QPushButton; -class QRadioButton; -class ViewProperties; -class DolphinView; - -/** - * @brief Dialog for changing the current view properties of a directory. - * - * It is possible to specify the view mode, the sorting order, whether hidden files - * and previews should be shown. The properties can be assigned to the current folder, - * or recursively to all sub folders. - */ -class LIBDOLPHINPRIVATE_EXPORT ViewPropertiesDialog : public KDialog -{ - Q_OBJECT - -public: - explicit ViewPropertiesDialog(DolphinView* dolphinView); - virtual ~ViewPropertiesDialog(); - -private slots: - void slotOk(); - void slotApply(); - void slotViewModeChanged(int index); - void slotSortingChanged(int index); - void slotSortOrderChanged(int index); - void slotCategorizedSortingChanged(); - void slotShowPreviewChanged(); - void slotShowHiddenFilesChanged(); - void markAsDirty(); - void configureAdditionalInfo(); - -private: - void applyViewProperties(); - void loadSettings(); - -private: - bool m_isDirty; - DolphinView* m_dolphinView; - ViewProperties* m_viewProps; - - KComboBox* m_viewMode; - KComboBox* m_sortOrder; - KComboBox* m_sorting; - QCheckBox* m_showPreview; - QCheckBox* m_showInGroups; - QCheckBox* m_showHiddenFiles; - QPushButton* m_additionalInfo; - QRadioButton* m_applyToCurrentFolder; - QRadioButton* m_applyToSubFolders; - QRadioButton* m_applyToAllFolders; - QCheckBox* m_useAsDefault; -}; - -#endif diff --git a/src/viewpropsprogressinfo.cpp b/src/viewpropsprogressinfo.cpp deleted file mode 100644 index c073d3d46..000000000 --- a/src/viewpropsprogressinfo.cpp +++ /dev/null @@ -1,148 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2006 by Peter Penz * - * peter.penz@gmx.at * - * * - * 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 of the License, 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. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#include "viewpropsprogressinfo.h" -#include "applyviewpropsjob.h" -#include "viewproperties.h" - -#include -#include -#include -#include - -#include -#include -#include - -ViewPropsProgressInfo::ViewPropsProgressInfo(QWidget* parent, - const KUrl& dir, - const ViewProperties& viewProps) : - KDialog(parent), - m_dir(dir), - m_viewProps(0), - m_label(0), - m_progressBar(0), - m_dirSizeJob(0), - m_applyViewPropsJob(0), - m_timer(0) -{ - const QSize minSize = minimumSize(); - setMinimumSize(QSize(320, minSize.height())); - - setCaption(i18nc("@title:window", "Applying View Properties")); - setButtons(KDialog::Cancel); - - m_viewProps = new ViewProperties(dir); - m_viewProps->setDirProperties(viewProps); - - // the view properties are stored by the ViewPropsApplierJob, so prevent - // that the view properties are saved twice: - m_viewProps->setAutoSaveEnabled(false); - - QWidget* main = new QWidget(); - QVBoxLayout* topLayout = new QVBoxLayout(); - - m_label = new QLabel(i18nc("@info:progress", "Counting folders: %1", 0), main); - m_progressBar = new QProgressBar(main); - m_progressBar->setMinimum(0); - m_progressBar->setMaximum(0); - m_progressBar->setValue(0); - - topLayout->addWidget(m_label); - topLayout->addWidget(m_progressBar); - - main->setLayout(topLayout); - setMainWidget(main); - - // Use the directory size job to count the number of directories first. This - // allows to give a progress indication for the user when applying the view - // properties later. - m_dirSizeJob = KIO::directorySize(dir); - connect(m_dirSizeJob, SIGNAL(result(KJob*)), - this, SLOT(applyViewProperties())); - - // The directory size job cannot emit any progress signal, as it is not aware - // about the total number of directories. Therefor a timer is triggered, which - // periodically updates the current directory count. - m_timer = new QTimer(this); - connect(m_timer, SIGNAL(timeout()), - this, SLOT(updateProgress())); - m_timer->start(300); - - connect(this, SIGNAL(cancelClicked()), this, SLOT(cancelApplying())); -} - -ViewPropsProgressInfo::~ViewPropsProgressInfo() -{ - delete m_viewProps; - m_viewProps = 0; -} - -void ViewPropsProgressInfo::closeEvent(QCloseEvent* event) -{ - m_timer->stop(); - m_applyViewPropsJob = 0; - KDialog::closeEvent(event); -} - -void ViewPropsProgressInfo::updateProgress() -{ - if (m_dirSizeJob != 0) { - const int subdirs = m_dirSizeJob->totalSubdirs(); - m_label->setText(i18nc("@info:progress", "Counting folders: %1", subdirs)); - } - - if (m_applyViewPropsJob != 0) { - const int progress = m_applyViewPropsJob->progress(); - m_progressBar->setValue(progress); - } -} - -void ViewPropsProgressInfo::applyViewProperties() -{ - if (m_dirSizeJob->error()) { - return; - } - - const int subdirs = m_dirSizeJob->totalSubdirs(); - m_label->setText(i18nc("@info:progress", "Folders: %1", subdirs)); - m_progressBar->setMaximum(subdirs); - - m_dirSizeJob = 0; - - m_applyViewPropsJob = new ApplyViewPropsJob(m_dir, *m_viewProps); - connect(m_applyViewPropsJob, SIGNAL(result(KJob*)), - this, SLOT(close())); -} - -void ViewPropsProgressInfo::cancelApplying() -{ - if (m_dirSizeJob != 0) { - m_dirSizeJob->kill(); - m_dirSizeJob = 0; - } - - if (m_applyViewPropsJob != 0) { - m_applyViewPropsJob->kill(); - m_applyViewPropsJob = 0; - } -} - -#include "viewpropsprogressinfo.moc" diff --git a/src/viewpropsprogressinfo.h b/src/viewpropsprogressinfo.h deleted file mode 100644 index d07d16d67..000000000 --- a/src/viewpropsprogressinfo.h +++ /dev/null @@ -1,78 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2006 by Peter Penz * - * peter.penz@gmx.at * - * * - * 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 of the License, 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. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ -#ifndef VIEWPROPSPROGRESSINFO_H -#define VIEWPROPSPROGRESSINFO_H - -#include -#include -#include - -class ApplyViewPropsJob; -class QLabel; -class QProgressBar; -class QTimer; -class ViewProperties; - -/** - * @brief Shows the progress information when applying view properties - * recursively to a given directory. - * - * It is possible to cancel the applying. In this case the already applied - * view properties won't get reverted. - */ -class ViewPropsProgressInfo : public KDialog -{ - Q_OBJECT - -public: - /** - * @param parent Parent widget of the dialog. - * @param dir Directory where the view properties should be applied to - * (including sub directories). - * @param viewProps View properties for the directory \a dir including its - * sub directories. - */ - ViewPropsProgressInfo(QWidget* parent, - const KUrl& dir, - const ViewProperties& viewProps); - - virtual ~ViewPropsProgressInfo(); - -protected: - virtual void closeEvent(QCloseEvent* event); - -private slots: - void updateProgress(); - void applyViewProperties(); - void cancelApplying(); - -private: - KUrl m_dir; - ViewProperties* m_viewProps; - - QLabel* m_label; - QProgressBar* m_progressBar; - - KIO::DirectorySizeJob* m_dirSizeJob; - ApplyViewPropsJob* m_applyViewPropsJob; - QTimer* m_timer; -}; - -#endif diff --git a/src/viewsettingspage.cpp b/src/viewsettingspage.cpp deleted file mode 100644 index bef05f58f..000000000 --- a/src/viewsettingspage.cpp +++ /dev/null @@ -1,98 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2006 by Peter Penz * - * peter.penz@gmx.at * - * * - * 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 of the License, 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. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#include "viewsettingspage.h" - -#include "columnviewsettingspage.h" -#include "detailsviewsettingspage.h" -#include "dolphinmainwindow.h" -#include "dolphinviewcontainer.h" -#include "generalviewsettingspage.h" -#include "iconsviewsettingspage.h" - -#include -#include -#include - -#include -#include -#include -#include - - -ViewSettingsPage::ViewSettingsPage(DolphinMainWindow* mainWindow, - QWidget* parent) : - SettingsPageBase(parent), - m_pages() -{ - QVBoxLayout* topLayout = new QVBoxLayout(this); - topLayout->setMargin(0); - topLayout->setSpacing(KDialog::spacingHint()); - - KTabWidget* tabWidget = new KTabWidget(this); - - // initialize 'General' tab - const KUrl& url = mainWindow->activeViewContainer()->url(); - GeneralViewSettingsPage* generalPage = new GeneralViewSettingsPage(url, tabWidget); - tabWidget->addTab(generalPage, KIcon("view-choose"), i18nc("@title:tab General settings", "General")); - connect(generalPage, SIGNAL(changed()), this, SIGNAL(changed())); - - // initialize 'Icons' tab - IconsViewSettingsPage* iconsPage = new IconsViewSettingsPage(tabWidget); - tabWidget->addTab(iconsPage, KIcon("view-list-icons"), i18nc("@title:tab", "Icons")); - connect(iconsPage, SIGNAL(changed()), this, SIGNAL(changed())); - - // initialize 'Details' tab - DetailsViewSettingsPage* detailsPage = new DetailsViewSettingsPage(tabWidget); - tabWidget->addTab(detailsPage, KIcon("view-list-details"), i18nc("@title:tab", "Details")); - connect(detailsPage, SIGNAL(changed()), this, SIGNAL(changed())); - - // initialize 'Column' tab - ColumnViewSettingsPage* columnPage = new ColumnViewSettingsPage(tabWidget); - tabWidget->addTab(columnPage, KIcon("view-file-columns"), i18nc("@title:tab", "Column")); - connect(columnPage, SIGNAL(changed()), this, SIGNAL(changed())); - - m_pages.append(generalPage); - m_pages.append(iconsPage); - m_pages.append(detailsPage); - m_pages.append(columnPage); - - topLayout->addWidget(tabWidget, 0, 0); -} - -ViewSettingsPage::~ViewSettingsPage() -{ -} - -void ViewSettingsPage::applySettings() -{ - foreach (ViewSettingsPageBase* page, m_pages) { - page->applySettings(); - } -} - -void ViewSettingsPage::restoreDefaults() -{ - foreach (ViewSettingsPageBase* page, m_pages) { - page->restoreDefaults(); - } -} - -#include "viewsettingspage.moc" diff --git a/src/viewsettingspage.h b/src/viewsettingspage.h deleted file mode 100644 index 21ce40039..000000000 --- a/src/viewsettingspage.h +++ /dev/null @@ -1,53 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2006 by Peter Penz * - * peter.penz@gmx.at * - * * - * 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 of the License, 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. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ -#ifndef VIEWSETTINGSPAGE_H -#define VIEWSETTINGSPAGE_H - -#include -#include - -class ViewSettingsPageBase; -class DolphinMainWindow; - -/** - * @brief Page for the 'View' settings of the Dolphin settings dialog. - * - * The views settings allow to set the properties for the icons mode, - * the details mode and the column mode. - */ -class ViewSettingsPage : public SettingsPageBase -{ - Q_OBJECT - -public: - ViewSettingsPage(DolphinMainWindow* mainWindow, QWidget* parent); - virtual ~ViewSettingsPage(); - - /** @see SettingsPageBase::applySettings() */ - virtual void applySettings(); - - /** @see SettingsPageBase::restoreDefaults() */ - virtual void restoreDefaults(); - -private: - QList m_pages; -}; - -#endif diff --git a/src/viewsettingspagebase.cpp b/src/viewsettingspagebase.cpp deleted file mode 100644 index b610bb0f5..000000000 --- a/src/viewsettingspagebase.cpp +++ /dev/null @@ -1,31 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Peter Penz * - * * - * 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 of the License, 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. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#include "viewsettingspagebase.h" - -ViewSettingsPageBase::ViewSettingsPageBase(QWidget* parent) : - KVBox(parent) -{ -} - -ViewSettingsPageBase::~ViewSettingsPageBase() -{ -} - -#include "viewsettingspagebase.moc" diff --git a/src/viewsettingspagebase.h b/src/viewsettingspagebase.h deleted file mode 100644 index 3e85e25cb..000000000 --- a/src/viewsettingspagebase.h +++ /dev/null @@ -1,55 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Peter Penz * - * * - * 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 of the License, 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. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#ifndef VIEWSETTINGSPAGEBASE_H -#define VIEWSETTINGSPAGEBASE_H - -#include - -/** - * @brief Base class for view settings configuration pages. - * - * @see GeneralViewSettingsPage; - * @see IconViewSettingsPage - * @see DetailsViewSettingsPage - * @see ColumnViewSettingsPage - */ -class ViewSettingsPageBase : public KVBox -{ - Q_OBJECT - -public: - ViewSettingsPageBase(QWidget* parent); - virtual ~ViewSettingsPageBase(); - - /** - * Applies the settings for the view. - * The settings are persisted automatically when - * closing Dolphin. - */ - virtual void applySettings() = 0; - - /** Restores the settings to default values. */ - virtual void restoreDefaults() = 0; - -signals: - void changed(); -}; - -#endif -- cgit v1.3