diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index 655e666d55..0c6d358268 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -191,16 +191,14 @@ void DolphinMainWindow::slotShowPreviewChanged() void DolphinMainWindow::slotShowHiddenFilesChanged() { - KToggleAction* showHiddenFilesAction = - static_cast(actionCollection()->action("show_hidden_files")); + QAction* showHiddenFilesAction = actionCollection()->action("show_hidden_files"); const DolphinView* view = m_activeViewContainer->view(); showHiddenFilesAction->setChecked(view->showHiddenFiles()); } void DolphinMainWindow::slotCategorizedSortingChanged() { - KToggleAction* showInGroupsAction = - static_cast(actionCollection()->action("show_in_groups")); + QAction* showInGroupsAction = actionCollection()->action("show_in_groups"); const DolphinView* view = m_activeViewContainer->view(); showInGroupsAction->setChecked(view->categorizedSorting()); showInGroupsAction->setEnabled(view->supportsCategorizedSorting()); @@ -244,14 +242,13 @@ void DolphinMainWindow::slotSortingChanged(DolphinView::Sorting sorting) } if (action != 0) { - KToggleAction* toggleAction = static_cast(action); - toggleAction->setChecked(true); + action->setChecked(true); } } void DolphinMainWindow::slotSortOrderChanged(Qt::SortOrder order) { - KToggleAction* descending = static_cast(actionCollection()->action("descending")); + QAction* descending = actionCollection()->action("descending"); const bool sortDescending = (order == Qt::DescendingOrder); descending->setChecked(sortDescending); } @@ -297,8 +294,7 @@ void DolphinMainWindow::slotHistoryChanged() void DolphinMainWindow::updateFilterBarAction(bool show) { - KToggleAction* showFilterBarAction = - static_cast(actionCollection()->action("show_filter_bar")); + QAction* showFilterBarAction = actionCollection()->action("show_filter_bar"); showFilterBarAction->setChecked(show); } @@ -605,11 +601,10 @@ void DolphinMainWindow::toggleSortOrder() m_activeViewContainer->view()->toggleSortOrder(); } -void DolphinMainWindow::toggleSortCategorization() +void DolphinMainWindow::toggleSortCategorization(bool categorizedSorting) { DolphinView* view = m_activeViewContainer->view(); - const bool categorizedSorting = view->categorizedSorting(); - view->setCategorizedSorting(!categorizedSorting); + view->setCategorizedSorting(categorizedSorting); } void DolphinMainWindow::toggleSplitView() @@ -657,31 +652,20 @@ void DolphinMainWindow::stopLoading() { } -void DolphinMainWindow::togglePreview() +void DolphinMainWindow::togglePreview(bool show) { clearStatusBar(); - - const KToggleAction* showPreviewAction = - static_cast(actionCollection()->action("show_preview")); - const bool show = showPreviewAction->isChecked(); m_activeViewContainer->view()->setShowPreview(show); } -void DolphinMainWindow::toggleShowHiddenFiles() +void DolphinMainWindow::toggleShowHiddenFiles(bool show) { clearStatusBar(); - - const KToggleAction* showHiddenFilesAction = - static_cast(actionCollection()->action("show_hidden_files")); - const bool show = showHiddenFilesAction->isChecked(); m_activeViewContainer->view()->setShowHiddenFiles(show); } -void DolphinMainWindow::toggleFilterBarVisibility() +void DolphinMainWindow::toggleFilterBarVisibility(bool show) { - const KToggleAction* showFilterBarAction = - static_cast(actionCollection()->action("show_filter_bar")); - const bool show = showFilterBarAction->isChecked(); m_activeViewContainer->showFilterBar(show); } @@ -701,11 +685,9 @@ void DolphinMainWindow::toggleEditLocation() { clearStatusBar(); - KToggleAction* action = static_cast(actionCollection()->action("editable_location")); - - bool editOrBrowse = action->isChecked(); + QAction* action = actionCollection()->action("editable_location"); KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator(); - urlNavigator->setUrlEditable(editOrBrowse); + urlNavigator->setUrlEditable(action->isChecked()); } void DolphinMainWindow::editLocation() @@ -978,6 +960,8 @@ void DolphinMainWindow::setupActions() viewModeGroup->addAction(columnView); connect(viewModeGroup, SIGNAL(triggered(QAction*)), this, SLOT(setViewMode(QAction*))); + // TODO use a QActionGroup + KToggleAction* sortByName = actionCollection()->add("sort_by_name"); sortByName->setText(i18nc("@action:inmenu Sort By", "Name")); connect(sortByName, SIGNAL(triggered()), this, SLOT(sortByName())); @@ -1046,22 +1030,17 @@ void DolphinMainWindow::setupActions() KAction* sortDescending = DolphinView::createSortDescendingAction(actionCollection()); connect(sortDescending, SIGNAL(triggered()), this, SLOT(toggleSortOrder())); - KToggleAction* showInGroups = actionCollection()->add("show_in_groups"); - showInGroups->setText(i18nc("@action:inmenu View", "Show in Groups")); - connect(showInGroups, SIGNAL(triggered()), this, SLOT(toggleSortCategorization())); + KAction* showInGroups = DolphinView::createShowInGroupsAction(actionCollection()); + connect(showInGroups, SIGNAL(triggered(bool)), this, SLOT(toggleSortCategorization(bool))); QActionGroup* showInformationActionGroup = DolphinView::createAdditionalInformationActionGroup(actionCollection()); connect(showInformationActionGroup, SIGNAL(triggered(QAction*)), this, SLOT(toggleAdditionalInfo(QAction*))); - KToggleAction* showPreview = actionCollection()->add("show_preview"); - showPreview->setText(i18nc("@action:intoolbar", "Preview")); - showPreview->setIcon(KIcon("view-preview")); - connect(showPreview, SIGNAL(triggered()), this, SLOT(togglePreview())); + KAction* showPreview = DolphinView::createShowPreviewAction(actionCollection()); + connect(showPreview, SIGNAL(triggered(bool)), this, SLOT(togglePreview(bool))); - KToggleAction* showHiddenFiles = actionCollection()->add("show_hidden_files"); - showHiddenFiles->setText(i18nc("@action:inmenu View", "Show Hidden Files")); - showHiddenFiles->setShortcut(Qt::ALT | Qt::Key_Period); - connect(showHiddenFiles, SIGNAL(triggered()), this, SLOT(toggleShowHiddenFiles())); + KAction* showHiddenFiles = DolphinView::createShowHiddenFilesAction(actionCollection()); + connect(showHiddenFiles, SIGNAL(triggered(bool)), this, SLOT(toggleShowHiddenFiles(bool))); KAction* split = actionCollection()->addAction("split_view"); split->setShortcut(Qt::Key_F3); @@ -1116,7 +1095,7 @@ void DolphinMainWindow::setupActions() KToggleAction* showFilterBar = actionCollection()->add("show_filter_bar"); showFilterBar->setText(i18nc("@action:inmenu Tools", "Show Filter Bar")); showFilterBar->setShortcut(Qt::CTRL | Qt::Key_I); - connect(showFilterBar, SIGNAL(triggered()), this, SLOT(toggleFilterBarVisibility())); + connect(showFilterBar, SIGNAL(triggered(bool)), this, SLOT(toggleFilterBarVisibility(bool))); KAction* compareFiles = actionCollection()->addAction("compare_files"); compareFiles->setText(i18nc("@action:inmenu Tools", "Compare Files")); @@ -1277,8 +1256,7 @@ void DolphinMainWindow::updateViewActions() QAction* action = actionCollection()->action(view->currentViewModeActionName()); if (action != 0) { - KToggleAction* toggleAction = static_cast(action); - toggleAction->setChecked(true); + action->setChecked(true); } slotSortingChanged(view->sorting()); @@ -1286,22 +1264,18 @@ void DolphinMainWindow::updateViewActions() slotCategorizedSortingChanged(); slotAdditionalInfoChanged(); - KToggleAction* showFilterBarAction = - static_cast(actionCollection()->action("show_filter_bar")); + QAction* showFilterBarAction = actionCollection()->action("show_filter_bar"); showFilterBarAction->setChecked(m_activeViewContainer->isFilterBarVisible()); - KToggleAction* showPreviewAction = - static_cast(actionCollection()->action("show_preview")); + QAction* showPreviewAction = actionCollection()->action("show_preview"); showPreviewAction->setChecked(view->showPreview()); - KToggleAction* showHiddenFilesAction = - static_cast(actionCollection()->action("show_hidden_files")); + QAction* showHiddenFilesAction = actionCollection()->action("show_hidden_files"); showHiddenFilesAction->setChecked(view->showHiddenFiles()); updateSplitAction(); - KToggleAction* editableLocactionAction = - static_cast(actionCollection()->action("editable_location")); + QAction* editableLocactionAction = actionCollection()->action("editable_location"); const KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator(); editableLocactionAction->setChecked(urlNavigator->isUrlEditable()); } diff --git a/src/dolphinmainwindow.h b/src/dolphinmainwindow.h index 444a4a9468..37cdcb43e8 100644 --- a/src/dolphinmainwindow.h +++ b/src/dolphinmainwindow.h @@ -271,7 +271,7 @@ private slots: void toggleSortOrder(); /** Switches between sorting by categories or not. */ - void toggleSortCategorization(); + void toggleSortCategorization(bool); /** * Switches on or off the displaying of additional information @@ -293,19 +293,17 @@ private slots: void stopLoading(); /** Switches between showing a preview of the file content and showing the icon. */ - void togglePreview(); + void togglePreview(bool); /** - * Switches between showing and hiding of hidden marked files dependent - * from the current state of the 'Show Hidden Files' menu toggle action. + * Switches between showing and hiding of hidden marked files */ - void toggleShowHiddenFiles(); + void toggleShowHiddenFiles(bool); /** - * Toggles between showing and hiding of the filter bar dependent - * from the current state of the 'Show Filter Bar' menu toggle action. + * Toggles between showing and hiding of the filter bar */ - void toggleFilterBarVisibility(); + void toggleFilterBarVisibility(bool show); /** Increases the size of the current set view mode. */ void zoomIn(); diff --git a/src/dolphinpart.cpp b/src/dolphinpart.cpp index f144109cbd..4d2eebcc63 100644 --- a/src/dolphinpart.cpp +++ b/src/dolphinpart.cpp @@ -93,6 +93,13 @@ DolphinPart::DolphinPart(QWidget* parentWidget, QObject* parent, const QStringLi this, SLOT(slotUrlChanged(KUrl))); connect(m_view, SIGNAL(modeChanged()), this, SLOT(updateViewActions())); + connect(m_view, SIGNAL(showPreviewChanged()), + this, SLOT(slotShowPreviewChanged())); + connect(m_view, SIGNAL(showHiddenFilesChanged()), + this, SLOT(slotShowHiddenFilesChanged())); + connect(m_view, SIGNAL(categorizedSortingChanged()), + this, SLOT(slotCategorizedSortingChanged())); + // TODO slotSortingChanged connect(m_view, SIGNAL(sortOrderChanged(Qt::SortOrder)), this, SLOT(slotSortOrderChanged(Qt::SortOrder))); connect(m_view, SIGNAL(additionalInfoChanged()), @@ -110,7 +117,6 @@ DolphinPart::DolphinPart(QWidget* parentWidget, QObject* parent, const QStringLi // [Q_PROPERTY introspection?] // TODO sort_by_* actions - // TODO show_*_info actions // TODO there was a "always open a new window" (when clicking on a directory) setting in konqueror // (sort of spacial navigation) @@ -158,6 +164,15 @@ void DolphinPart::createActions() QActionGroup* showInformationActionGroup = DolphinView::createAdditionalInformationActionGroup(actionCollection()); connect(showInformationActionGroup, SIGNAL(triggered(QAction*)), m_view, SLOT(toggleAdditionalInfo(QAction*))); + KAction* showPreview = DolphinView::createShowPreviewAction(actionCollection()); + connect(showPreview, SIGNAL(triggered(bool)), m_view, SLOT(setShowPreview(bool))); + + KAction* showInGroups = DolphinView::createShowInGroupsAction(actionCollection()); + connect(showInGroups, SIGNAL(triggered(bool)), m_view, SLOT(setCategorizedSorting(bool))); + + KAction* showHiddenFiles = DolphinView::createShowHiddenFilesAction(actionCollection()); + connect(showHiddenFiles, SIGNAL(triggered(bool)), m_view, SLOT(setShowHiddenFiles(bool))); + // Go menu KAction* newDirAction = DolphinView::createNewDirAction(actionCollection()); @@ -457,4 +472,25 @@ void DolphinPart::slotAdditionalInfoChanged() m_view->updateAdditionalInfoActions(actionCollection()); } +void DolphinPart::slotShowPreviewChanged() +{ + updateViewActions(); // see DolphinMainWindow +} + +void DolphinPart::slotShowHiddenFilesChanged() +{ + QAction* showHiddenFilesAction = actionCollection()->action("show_hidden_files"); + showHiddenFilesAction->setChecked(m_view->showHiddenFiles()); +} + +void DolphinPart::slotCategorizedSortingChanged() +{ + // Duplicated from DolphinMainWindow too. + QAction* showInGroupsAction = actionCollection()->action("show_in_groups"); + showInGroupsAction->setChecked(m_view->categorizedSorting()); + showInGroupsAction->setEnabled(m_view->supportsCategorizedSorting()); +} + +// TODO a DolphinViewActionHandler for reducing the duplication in the action handling + #include "dolphinpart.moc" diff --git a/src/dolphinpart.h b/src/dolphinpart.h index 3d9ec03069..797c34d71e 100644 --- a/src/dolphinpart.h +++ b/src/dolphinpart.h @@ -136,6 +136,15 @@ private Q_SLOTS: */ void createDir(); + /** Updates the state of the 'Show preview' menu action. */ + void slotShowPreviewChanged(); + + /** Updates the state of the 'Show hidden files' menu action. */ + void slotShowHiddenFilesChanged(); + + /** Updates the state of the 'Categorized sorting' menu action. */ + void slotCategorizedSortingChanged(); + /** Updates the state of the 'Sort Ascending/Descending' action. */ void slotSortOrderChanged(Qt::SortOrder); diff --git a/src/dolphinview.cpp b/src/dolphinview.cpp index b16a61e1b8..c94a4ea7f2 100644 --- a/src/dolphinview.cpp +++ b/src/dolphinview.cpp @@ -1224,6 +1224,29 @@ KAction* DolphinView::createSortDescendingAction(KActionCollection* collection) return sortDescending; } +KAction* DolphinView::createShowPreviewAction(KActionCollection* collection) +{ + KToggleAction* showPreview = collection->add("show_preview"); + showPreview->setText(i18nc("@action:intoolbar", "Preview")); + showPreview->setIcon(KIcon("view-preview")); + return showPreview; +} + +KAction* DolphinView::createShowInGroupsAction(KActionCollection* collection) +{ + KToggleAction* showInGroups = collection->add("show_in_groups"); + showInGroups->setText(i18nc("@action:inmenu View", "Show in Groups")); + return showInGroups; +} + +KAction* DolphinView::createShowHiddenFilesAction(KActionCollection* collection) +{ + KToggleAction* showHiddenFiles = collection->add("show_hidden_files"); + showHiddenFiles->setText(i18nc("@action:inmenu View", "Show Hidden Files")); + showHiddenFiles->setShortcut(Qt::ALT | Qt::Key_Period); + return showHiddenFiles; +} + QActionGroup* DolphinView::createAdditionalInformationActionGroup(KActionCollection* collection) { QActionGroup* showInformationGroup = new QActionGroup(collection); diff --git a/src/dolphinview.h b/src/dolphinview.h index 6f26585698..201cc0785a 100644 --- a/src/dolphinview.h +++ b/src/dolphinview.h @@ -164,39 +164,18 @@ public: * Changes the view mode for the current directory to \a mode. * If the view properties should be remembered for each directory * (GeneralSettings::globalViewProps() returns false), then the - * changed view mode will be be stored automatically. + * changed view mode will be stored automatically. */ void setMode(Mode mode); Mode mode() const; - /** - * Turns on the file preview for the all files of the current directory, - * if \a show is true. - * If the view properties should be remembered for each directory - * (GeneralSettings::globalViewProps() returns false), then the - * preview setting will be be stored automatically. - */ - void setShowPreview(bool show); + /** See setShowPreview */ bool showPreview() const; - /** - * Shows all hidden files of the current directory, - * if \a show is true. - * If the view properties should be remembered for each directory - * (GeneralSettings::globalViewProps() returns false), then the - * show hidden file setting will be be stored automatically. - */ - void setShowHiddenFiles(bool show); + /** See setShowHiddenFiles */ bool showHiddenFiles() const; - /** - * Summarizes all sorted items by their category \a categorized - * is true. - * If the view properties should be remembered for each directory - * (GeneralSettings::globalViewProps() returns false), then the - * categorized sorting setting will be be stored automatically. - */ - void setCategorizedSorting(bool categorized); + /** See setCategorizedSorting */ bool categorizedSorting() const; /** @@ -379,6 +358,24 @@ public: */ static QActionGroup* createAdditionalInformationActionGroup(KActionCollection* collection); + /** + * Creates the "show preview" action. + * This code is here to share it between the mainwindow and the part + */ + static KAction* createShowPreviewAction(KActionCollection* collection); + + /** + * Creates the "show in groups" action. + * This code is here to share it between the mainwindow and the part + */ + static KAction* createShowInGroupsAction(KActionCollection* collection); + + /** + * Creates the "show hidden files" action. + * This code is here to share it between the mainwindow and the part + */ + static KAction* createShowHiddenFilesAction(KActionCollection* collection); + /** * Updates the state of the 'Additional Information' actions in \a collection. */ @@ -439,6 +436,33 @@ public slots: /** Pastes the clipboard data to this view. */ void paste(); + /** + * Turns on the file preview for the all files of the current directory, + * if \a show is true. + * If the view properties should be remembered for each directory + * (GeneralSettings::globalViewProps() returns false), then the + * preview setting will be stored automatically. + */ + void setShowPreview(bool show); + + /** + * Shows all hidden files of the current directory, + * if \a show is true. + * If the view properties should be remembered for each directory + * (GeneralSettings::globalViewProps() returns false), then the + * show hidden file setting will be stored automatically. + */ + void setShowHiddenFiles(bool show); + + /** + * Summarizes all sorted items by their category \a categorized + * is true. + * If the view properties should be remembered for each directory + * (GeneralSettings::globalViewProps() returns false), then the + * categorized sorting setting will be stored automatically. + */ + void setCategorizedSorting(bool categorized); + /** Switches between an ascending and descending sorting order. */ void toggleSortOrder();