)
kde4_add_kcfg_files(dolphinprivate_LIB_SRCS
- dolphin_directoryviewpropertysettings.kcfgc
+ dolphin_directoryviewpropertysettings.kcfgc
dolphin_detailsmodesettings.kcfgc
dolphin_iconsmodesettings.kcfgc
dolphin_generalsettings.kcfgc)
sidebarpage.cpp
statusbarspaceinfo.cpp
statusbarmessagelabel.cpp
+ treeviewcontextmenu.cpp
treeviewsidebarpage.cpp
sidebartreeview.cpp
urlbutton.cpp
#include <klocale.h>
#include "dolphinsettings.h"
-#include "dolphinmainwindow.h"
#include "editbookmarkdialog.h"
-BookmarksSidebarPage::BookmarksSidebarPage(DolphinMainWindow* mainWindow, QWidget* parent) :
- SidebarPage(mainWindow, parent)
+BookmarksSidebarPage::BookmarksSidebarPage(QWidget* parent) :
+ SidebarPage(parent)
{
Q3VBoxLayout* layout = new Q3VBoxLayout(this);
m_bookmarksList = new BookmarksListBox(this);
{
}
-void BookmarksSidebarPage::activeViewChanged()
+void BookmarksSidebarPage::setUrl(const KUrl& url)
{
- connectToActiveView();
+ if (!m_url.equals(url, KUrl::CompareWithoutTrailingSlash)) {
+ m_url = url;
+ adjustSelection(m_url);
+ }
}
void BookmarksSidebarPage::updateBookmarks()
bookmark = root.next(bookmark);
}
-
- connectToActiveView();
}
void BookmarksSidebarPage::slotMouseButtonClicked(int button, Q3ListBoxItem* item)
const int index = m_bookmarksList->index(item);
KBookmark bookmark = DolphinSettings::instance().bookmark(index);
- mainWindow()->activeView()->setUrl(bookmark.url());
+ emit changeUrl(bookmark.url());
}
void BookmarksSidebarPage::slotContextMenuRequested(Q3ListBoxItem* item,
}
delete popup;
popup = 0;
-
- DolphinView* view = mainWindow()->activeView();
- adjustSelection(view->url());
}
m_bookmarksList->blockSignals(block);
}
-void BookmarksSidebarPage::slotUrlChanged(const KUrl& url)
-{
- adjustSelection(url);
-}
-
-void BookmarksSidebarPage::connectToActiveView()
-{
- DolphinView* view = mainWindow()->activeView();
- adjustSelection(view->url());
- connect(view, SIGNAL(urlChanged(const KUrl&)),
- this, SLOT(slotUrlChanged(const KUrl&)));
-}
-
BookmarksListBox::BookmarksListBox(QWidget* parent) :
Q3ListBox(parent)
{
#ifndef _BOOKMARKSSIDEBARPAGE_H_
#define _BOOKMARKSSIDEBARPAGE_H_
-#include <sidebarpage.h>
#include <q3listbox.h>
//Added by qt3to4:
#include <QPaintEvent>
#include <QPixmap>
+#include "sidebarpage.h"
+
class KUrl;
class BookmarksListBox;
Q_OBJECT
public:
- BookmarksSidebarPage(DolphinMainWindow *mainWindow, QWidget* parent=0);
+ BookmarksSidebarPage(QWidget* parent=0);
virtual ~BookmarksSidebarPage();
-protected:
- /** @see SidebarPage::activeViewChanged() */
- virtual void activeViewChanged();
+public slots:
+ void setUrl(const KUrl& url);
private slots:
/** Fills the listbox with the bookmarks stored in DolphinSettings. */
/** @see QListBox::slotContextMenuRequested */
void slotContextMenuRequested(Q3ListBoxItem* item, const QPoint& pos);
- /**
- * Is invoked whenever the Url of the active view has been changed. Adjusts
- * the selection of the listbox to the bookmark which is part of the current Url.
- */
- void slotUrlChanged(const KUrl& url);
-
private:
/**
* Updates the selection dependent from the given Url \a url. The
*/
void adjustSelection(const KUrl& url);
- /**
- * Connects to signals from the currently active Dolphin view to get
- * informed about Url and bookmark changes.
- */
- void connectToActiveView();
-
BookmarksListBox* m_bookmarksList;
};
DolphinContextMenu::DolphinContextMenu(DolphinMainWindow* parent,
KFileItem* fileInfo,
- const KUrl& baseUrl,
- ViewType viewType) :
+ const KUrl& baseUrl) :
m_mainWindow(parent),
m_fileInfo(fileInfo),
m_baseUrl(baseUrl),
- m_viewType(viewType),
m_context(NoContext)
{
- if (viewType == ItemsView) {
- // The context menu either accesses the URLs of the selected items
- // or the items itself. To increase the performance both lists are cached.
- DolphinView* view = m_mainWindow->activeView();
- m_selectedUrls = view->selectedUrls();
- m_selectedItems = view->selectedItems();
- }
- else if (fileInfo != 0) {
- m_selectedUrls.append(fileInfo->url());
- m_selectedItems.append(fileInfo);
- }
+ // The context menu either accesses the URLs of the selected items
+ // or the items itself. To increase the performance both lists are cached.
+ DolphinView* view = m_mainWindow->activeView();
+ m_selectedUrls = view->selectedUrls();
+ m_selectedItems = view->selectedItems();
}
DolphinContextMenu::~DolphinContextMenu()
}
}
-void DolphinContextMenu::cut()
-{
- QMimeData* mimeData = new QMimeData();
- KUrl::List kdeUrls;
- kdeUrls.append(m_fileInfo->url());
- KonqMimeData::populateMimeData(mimeData, kdeUrls, KUrl::List(), true);
- QApplication::clipboard()->setMimeData(mimeData);
-}
-
-void DolphinContextMenu::copy()
-{
- QMimeData* mimeData = new QMimeData();
- KUrl::List kdeUrls;
- kdeUrls.append(m_fileInfo->url());
- KonqMimeData::populateMimeData(mimeData, kdeUrls, KUrl::List(), false);
- QApplication::clipboard()->setMimeData(mimeData);
-}
-
-void DolphinContextMenu::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_mainWindow, KonqOperations::MOVE, source, dest);
- clipboard->clear();
- }
- else {
- KonqOperations::copy(m_mainWindow, KonqOperations::COPY, source, dest);
- }
-}
-
-void DolphinContextMenu::rename()
-{
- // TODO
-}
-
-void DolphinContextMenu::moveToTrash()
-{
- // TODO
-}
-
-void DolphinContextMenu::deleteItem()
-{
- // TODO
-}
-
-void DolphinContextMenu::showProperties()
-{
- new KPropertiesDialog(m_fileInfo->url());
-}
void DolphinContextMenu::openTrashContextMenu()
{
popup->addSeparator();
// insert 'Properties...' entry
- QAction* propertiesAction = 0;
- if (m_viewType == SidebarView) {
- propertiesAction = new QAction(i18n("Properties..."), this);
- connect(this, SIGNAL(triggered()), this, SLOT(showProperties()));
- }
- else {
- propertiesAction = m_mainWindow->actionCollection()->action("properties");
- }
+ QAction* propertiesAction = m_mainWindow->actionCollection()->action("properties");
popup->addAction(propertiesAction);
QAction* activatedAction = popup->exec(QCursor::pos());
{
Q_ASSERT(popup != 0);
const KActionCollection* collection = m_mainWindow->actionCollection();
- const bool insertSidebarActions = (m_viewType == SidebarView);
// insert 'Cut', 'Copy' and 'Paste'
- QAction* cutAction = 0;
- QAction* copyAction = 0;
- QAction* pasteAction = 0;
- if (insertSidebarActions) {
- cutAction = new QAction(KIcon("edit-cut"), i18n("Cut"), this);
- connect(cutAction, SIGNAL(triggered()), this, SLOT(cut()));
-
- copyAction = new QAction(KIcon("edit-copy"), i18n("Copy"), this);
- connect(copyAction, SIGNAL(triggered()), this, SLOT(copy()));
-
- const QAction* menuPasteAction = collection->action(KStandardAction::stdName(KStandardAction::Paste));
- pasteAction = new QAction(KIcon("edit-paste"), menuPasteAction->text(), this);
- pasteAction->setEnabled(menuPasteAction->isEnabled());
- connect(pasteAction, SIGNAL(triggered()), this, SLOT(paste()));
- }
- else {
- cutAction = collection->action(KStandardAction::stdName(KStandardAction::Cut));
- copyAction = collection->action(KStandardAction::stdName(KStandardAction::Copy));
- pasteAction = collection->action(KStandardAction::stdName(KStandardAction::Paste));
- }
+ QAction* cutAction = collection->action(KStandardAction::stdName(KStandardAction::Cut));
+ QAction* copyAction = collection->action(KStandardAction::stdName(KStandardAction::Copy));
+ QAction* pasteAction = collection->action(KStandardAction::stdName(KStandardAction::Paste));
popup->addAction(cutAction);
popup->addAction(copyAction);
popup->addSeparator();
// insert 'Rename'
- QAction* renameAction = 0;
- if (insertSidebarActions) {
- renameAction = new QAction(i18n("Rename"), this);
- connect(renameAction, SIGNAL(triggered()), this, SLOT(rename()));
- }
- else {
- renameAction = collection->action("rename");
- }
+ QAction* renameAction = collection->action("rename");
popup->addAction(renameAction);
// insert 'Move to Trash' and (optionally) 'Delete'
const KSharedConfig::Ptr globalConfig = KSharedConfig::openConfig("kdeglobals", KConfig::NoGlobals);
const KConfigGroup kdeConfig(globalConfig, "KDE");
bool showDeleteCommand = kdeConfig.readEntry("ShowDeleteCommand", false);
- const KUrl& url = insertSidebarActions ? m_fileInfo->url():
- m_mainWindow->activeView()->url();
+ const KUrl& url = m_mainWindow->activeView()->url();
if (url.isLocalFile()) {
- QAction* moveToTrashAction = 0;
- if (insertSidebarActions) {
- moveToTrashAction = new QAction(KIcon("edit-trash"), i18n("Move To Trash"), this);
- connect(moveToTrashAction, SIGNAL(triggered()), this, SLOT(moveToTrash()));
- }
- else {
- moveToTrashAction = collection->action("move_to_trash");
- }
+ QAction* moveToTrashAction = collection->action("move_to_trash");
popup->addAction(moveToTrashAction);
}
else {
}
if (showDeleteCommand) {
- QAction* deleteAction = 0;
- if (insertSidebarActions) {
- deleteAction = new QAction(KIcon("edit-delete"), i18n("Delete"), this);
- connect(deleteAction, SIGNAL(triggered()), this, SLOT(deleteItem()));
- }
- else {
- deleteAction = collection->action("delete");
- }
+ QAction* deleteAction = collection->action("delete");
popup->addAction(deleteAction);
}
}
Q_OBJECT
public:
- enum ViewType
- {
- ItemsView,
- SidebarView
- };
-
/**
* @parent Pointer to the main window the context menu
* belongs to.
*/
DolphinContextMenu(DolphinMainWindow* parent,
KFileItem* fileInfo,
- const KUrl& baseUrl,
- ViewType viewType = ItemsView);
+ const KUrl& baseUrl);
virtual ~DolphinContextMenu();
/** 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();
-
private:
void openTrashContextMenu();
void openTrashItemContextMenu();
KUrl m_baseUrl;
KFileItemList m_selectedItems;
KUrl::List m_selectedUrls;
- ViewType m_viewType;
int m_context;
};
emit activeViewChanged();\r
}\r
\r
-void DolphinMainWindow::changeUrl(const QString& url)\r
+void DolphinMainWindow::changeUrl(const KUrl& url)\r
{\r
if (activeView() != 0) {\r
- activeView()->setUrl(KUrl(url));\r
+ activeView()->setUrl(url);\r
+ updateEditActions();\r
+ updateViewActions();\r
+ updateGoActions();\r
+ setCaption(url.fileName());\r
+ emit urlChanged(url);\r
}\r
}\r
\r
+void DolphinMainWindow::changeSelection(const KFileItemList& selection)\r
+{\r
+ activeView()->changeSelection(selection);\r
+}\r
+\r
void DolphinMainWindow::slotViewModeChanged()\r
{\r
updateViewActions();\r
}\r
}\r
\r
-void DolphinMainWindow::slotSelectionChanged()\r
+void DolphinMainWindow::slotSelectionChanged(const KFileItemList& selection)\r
{\r
updateEditActions();\r
\r
\r
m_activeView->updateStatusBar();\r
\r
- emit selectionChanged();\r
+ emit selectionChanged(selection);\r
}\r
\r
void DolphinMainWindow::slotHistoryChanged()\r
updateHistory();\r
}\r
\r
-void DolphinMainWindow::slotUrlChanged(const KUrl& url)\r
-{\r
- updateEditActions();\r
- updateViewActions();\r
- updateGoActions();\r
- setCaption(url.fileName());\r
-}\r
-\r
void DolphinMainWindow::updateFilterBarAction(bool show)\r
{\r
KToggleAction* showFilterBarAction =\r
connectViewSignals(SecondaryIdx);\r
m_splitter->addWidget(m_view[SecondaryIdx]);\r
m_splitter->setSizes(QList<int>() << newWidth << newWidth);\r
+ m_view[SecondaryIdx]->reload();\r
m_view[SecondaryIdx]->show();\r
}\r
else {\r
homeUrl,\r
props.viewMode(),\r
props.showHiddenFiles());\r
- connectViewSignals(PrimaryIdx);\r
- m_view[PrimaryIdx]->show();\r
\r
m_activeView = m_view[PrimaryIdx];\r
+ connectViewSignals(PrimaryIdx);\r
+ m_view[PrimaryIdx]->reload();\r
+ m_view[PrimaryIdx]->show();\r
\r
setCentralWidget(m_splitter);\r
setupDockWidgets();\r
if ( !MetaDataWidget::metaDataAvailable() )\r
activeView()->statusBar()->setMessage(i18n("Failed to contact Nepomuk service, annotation and tagging are disabled."), DolphinStatusBar::Error);\r
#endif\r
+\r
+ emit urlChanged(homeUrl);\r
}\r
\r
void DolphinMainWindow::loadSettings()\r
// after the dock concept has been finalized.\r
\r
// setup "Bookmarks"\r
- QDockWidget* shortcutsDock = new QDockWidget(i18n("Bookmarks"));\r
+ QDockWidget* shortcutsDock = new QDockWidget(i18n("Bookmarks"), this);\r
shortcutsDock->setObjectName("bookmarksDock");\r
shortcutsDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);\r
- shortcutsDock->setWidget(new BookmarksSidebarPage(this));\r
+ SidebarPage* shortcutsWidget = new BookmarksSidebarPage(shortcutsDock);\r
+ shortcutsDock->setWidget(shortcutsWidget);\r
+\r
\r
shortcutsDock->toggleViewAction()->setText(i18n("Show Bookmarks Panel"));\r
actionCollection()->addAction("show_bookmarks_panel", shortcutsDock->toggleViewAction());\r
\r
addDockWidget(Qt::LeftDockWidgetArea, shortcutsDock);\r
+ connectSidebarPage(shortcutsWidget);\r
\r
// setup "Information"\r
- QDockWidget* infoDock = new QDockWidget(i18n("Information"));\r
+ QDockWidget* infoDock = new QDockWidget(i18n("Information"), this);\r
infoDock->setObjectName("infoDock");\r
infoDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);\r
- infoDock->setWidget(new InfoSidebarPage(this));\r
+ SidebarPage* infoWidget = new InfoSidebarPage(infoDock);\r
+ infoDock->setWidget(infoWidget);\r
+\r
\r
infoDock->toggleViewAction()->setText(i18n("Show Information Panel"));\r
actionCollection()->addAction("show_info_panel", infoDock->toggleViewAction());\r
\r
addDockWidget(Qt::RightDockWidgetArea, infoDock);\r
+ connectSidebarPage(infoWidget);\r
\r
// setup "Tree View"\r
QDockWidget* treeViewDock = new QDockWidget(i18n("Folders")); // TODO: naming?\r
treeViewDock->setObjectName("treeViewDock");\r
treeViewDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);\r
- treeViewDock->setWidget(new TreeViewSidebarPage(this));\r
+ TreeViewSidebarPage* treeWidget = new TreeViewSidebarPage(treeViewDock);\r
+ treeViewDock->setWidget(treeWidget);\r
\r
treeViewDock->toggleViewAction()->setText(i18n("Show Folders Panel"));\r
actionCollection()->addAction("show_folders_panel", treeViewDock->toggleViewAction());\r
\r
addDockWidget(Qt::LeftDockWidgetArea, treeViewDock);\r
+ connectSidebarPage(treeWidget);\r
\r
const bool firstRun = DolphinSettings::instance().generalSettings()->firstRun();\r
if (firstRun) {\r
this, SLOT(slotSortOrderChanged(Qt::SortOrder)));\r
connect(view, SIGNAL(additionalInfoChanged(KFileItemDelegate::AdditionalInformation)),\r
this, SLOT(slotAdditionalInfoChanged(KFileItemDelegate::AdditionalInformation)));\r
- connect(view, SIGNAL(selectionChanged()),\r
- this, SLOT(slotSelectionChanged()));\r
+ connect(view, SIGNAL(selectionChanged(KFileItemList)),\r
+ this, SLOT(slotSelectionChanged(KFileItemList)));\r
connect(view, SIGNAL(showFilterBarChanged(bool)),\r
this, SLOT(updateFilterBarAction(bool)));\r
+ connect(view, SIGNAL(urlChanged(KUrl)),\r
+ this, SLOT(changeUrl(KUrl)));\r
\r
const UrlNavigator* navigator = view->urlNavigator();\r
connect(navigator, SIGNAL(urlChanged(const KUrl&)),\r
- this, SLOT(slotUrlChanged(const KUrl&)));\r
+ this, SLOT(changeUrl(const KUrl&)));\r
connect(navigator, SIGNAL(historyChanged()),\r
this, SLOT(slotHistoryChanged()));\r
+}\r
+void DolphinMainWindow::connectSidebarPage(SidebarPage* page)\r
+{\r
+ connect(page, SIGNAL(changeUrl(KUrl)),\r
+ this, SLOT(changeUrl(KUrl)));\r
+ connect(page, SIGNAL(changeSelection(KFileItemList)),\r
+ this, SLOT(changeSelection(KFileItemList)));\r
+ connect(page, SIGNAL(urlsDropped(KUrl::List,KUrl)),\r
+ this, SLOT(dropUrls(KUrl::List,KUrl)));\r
\r
+ connect(this, SIGNAL(urlChanged(KUrl)),\r
+ page, SLOT(setUrl(KUrl)));\r
+ connect(this, SIGNAL(selectionChanged(KFileItemList)),\r
+ page, SLOT(setSelection(KFileItemList)));\r
}\r
\r
DolphinMainWindow::UndoUiInterface::UndoUiInterface(DolphinMainWindow* mainWin) :\r
#define DOLPHIN_MAINWINDOW_H
#include "dolphinview.h"
+#include "sidebarpage.h"
#include <kmainwindow.h>
#include <ksortablelist.h>
*/
DolphinView* activeView() const { return m_activeView; }
- /**
- * Handles the dropping of URLs to the given
- * destination. A context menu with the options
- * 'Move Here', 'Copy Here', 'Link Here' and
- * 'Cancel' is offered to the user.
- * @param urls List of URLs which have been
- * dropped.
- * @param destination Destination URL, where the
- * list or URLs should be moved,
- * copied or linked to.
- */
- void dropUrls(const KUrl::List& urls,
- const KUrl& destination);
-
/** Renames the item represented by \a oldUrl to \a newUrl. */
void rename(const KUrl& oldUrl, const KUrl& newUrl);
KNewMenu* newMenu() const { return m_newMenu; }
public slots:
+ /**
+ * Handles the dropping of URLs to the given
+ * destination. A context menu with the options
+ * 'Move Here', 'Copy Here', 'Link Here' and
+ * 'Cancel' is offered to the user.
+ * @param urls List of URLs which have been
+ * dropped.
+ * @param destination Destination URL, where the
+ * list or URLs should be moved,
+ * copied or linked to.
+ */
+ void dropUrls(const KUrl::List& urls,
+ const KUrl& destination);
+
/**
* Returns the main window ID used through DBus.
*/
int getId() const { return m_id; }
/**
- * Changes the URL of the current active DolphinView to \a url.
+ * Inform all affected dolphin components (sidebars, views) of an URL
+ * change.
+ */
+ void changeUrl(const KUrl& url);
+
+ /**
+ * Inform all affected dolphin components that a selection change is
+ * requested.
*/
- void changeUrl(const QString& url);
+ void changeSelection(const KFileItemList& selection);
/** Stores all settings and quits Dolphin. */
void quit();
void activeViewChanged();
/**
- * Is send if the selection of the currently active view has
+ * Is sent if the selection of the currently active view has
* been changed.
*/
- void selectionChanged();
+ void selectionChanged(const KFileItemList& selection);
+
+ /**
+ * Is sent if the url of the currently active view has
+ * been changed.
+ */
+ void urlChanged(const KUrl& url);
protected:
/** @see QMainWindow::closeEvent */
void slotAdditionalInfoChanged(KFileItemDelegate::AdditionalInformation info);
/** Updates the state of the 'Edit' menu actions. */
- void slotSelectionChanged();
+ void slotSelectionChanged(const KFileItemList& selection);
/**
* Updates the state of the 'Back' and 'Forward' menu
*/
void slotHistoryChanged();
- /**
- * Updates the caption of the main window and the state
- * of all menu actions which depend from a changed URL.
- */
- void slotUrlChanged(const KUrl& url);
-
/** Updates the state of the 'Show filter bar' menu action. */
void updateFilterBarAction(bool show);
*/
void connectViewSignals(int viewIndex);
+ /**
+ * Helper function to connect all signal/slots of the given \sidebar.
+ */
+ void connectSidebarPage(SidebarPage* sidebar);
+
private:
/**
* DolphinMainWindowsupports only one or two views, which
m_topLayout->addWidget(itemView());
m_topLayout->addWidget(m_filterBar);
m_topLayout->addWidget(m_statusBar);
-
- loadDirectory(m_urlNavigator->url());
}
DolphinView::~DolphinView()
void DolphinView::loadDirectory(const KUrl& url)
{
+ if(!isActive()) {
+ requestActivation();
+ }
+
const ViewProperties props(url);
const Mode mode = props.viewMode();
void DolphinView::emitSelectionChangedSignal()
{
- emit selectionChanged();
+ emit selectionChanged(DolphinView::selectedItems());
}
void DolphinView::closeFilterBar()
m_mainWindow->setActiveView(this);
}
+void DolphinView::changeSelection(const KFileItemList& selection)
+{
+ clearSelection();
+ if (selection.isEmpty()) {
+ return;
+ }
+ KUrl baseUrl = url();
+ KUrl url;
+ QItemSelection new_selection;
+ foreach (KFileItem* item, selection) {
+ url = item->url().upUrl();
+ if (baseUrl.equals(url, KUrl::CompareWithoutTrailingSlash)) {
+ QModelIndex index = m_proxyModel->mapFromSource(m_dirModel->indexForItem(*item));
+ new_selection.select(index, index);
+ }
+ }
+ itemView()->selectionModel()->select(new_selection,
+ QItemSelectionModel::ClearAndSelect
+ | QItemSelectionModel::Current);
+}
+
void DolphinView::changeNameFilter(const QString& nameFilter)
{
// The name filter of KDirLister does a 'hard' filtering, which
void DolphinView::updateActivationState()
{
m_urlNavigator->setActive(isActive());
+ if(isActive()) {
+ emit urlChanged(url());
+ emit selectionChanged(selectedItems());
+ }
}
void DolphinView::updateCutItems()
*/
void requestActivation();
+ /**
+ * Request of a selection change. The view will do its best to accomodate
+ * the request, but it is not guaranteed that all items in \a selection
+ * will actually get selected. The view will e.g. not select items which
+ * are not in the currently displayed folder.
+ */
+ void changeSelection(const KFileItemList& selection);
+
signals:
/** Is emitted if URL of the view has been changed to \a url. */
void urlChanged(const KUrl& url);
void contentsMoved(int x, int y);
/**
- * Is emitted whenever the selection has been changed. The current selection can
- * be retrieved by mainWindow()->activeView()->selectedItems() or by
- * mainWindow()->activeView()->selectedUrls().
+ * Is emitted whenever the selection has been changed.
*/
- void selectionChanged();
+ void selectionChanged(const KFileItemList& selection);
/**
* Is emitted whenever the filter bar has been turned show or hidden.
#include <config-kmetadata.h>
#include "infosidebarpage.h"
-#include <assert.h>
-#include <qlayout.h>
-#include <qpixmap.h>
-#include <qlabel.h>
-#include <qtimer.h>
-#include <qpushbutton.h>
-
-#include <qmenu.h>
-#include <qpainter.h>
-#include <qfontmetrics.h>
+#include <QLayout>
+#include <QPixmap>
+#include <QLabel>
+#include <QTimer>
+#include <QPushButton>
+#include <QMenu>
+#include <QPainter>
+#include <QFontMetrics>
#include <QEvent>
#include <QInputDialog>
+#include <QDir>
#include <kbookmarkmanager.h>
#include <klocale.h>
#include <kfilemetainfo.h>
#include <kvbox.h>
#include <kseparator.h>
+#include <kiconloader.h>
#ifdef HAVE_KMETADATA
#include <kratingwidget.h>
#endif
-#include "dolphinmainwindow.h"
-#include "dolphinapplication.h"
#include "pixmapviewer.h"
#include "dolphinsettings.h"
#include "metadatawidget.h"
-InfoSidebarPage::InfoSidebarPage(DolphinMainWindow* mainWindow, QWidget* parent) :
- SidebarPage(mainWindow, parent),
- m_multipleSelection(false),
+InfoSidebarPage::InfoSidebarPage(QWidget* parent) :
+ SidebarPage(parent),
+ m_multipleSelection(false), //TODO:check if I'm needed
m_pendingPreview(false),
m_timer(0),
+ m_currentSelection(KFileItemList()),
m_preview(0),
m_name(0),
m_infos(0)
layout->addWidget(m_actionBox);
layout->addWidget(dummy);
setLayout(layout);
- connect(mainWindow, SIGNAL(selectionChanged()),
- this, SLOT(showItemInfo()));
-
- connectToActiveView();
}
InfoSidebarPage::~InfoSidebarPage()
{
}
-void InfoSidebarPage::activeViewChanged()
+void InfoSidebarPage::setUrl(const KUrl& url)
{
- connectToActiveView();
+ if (!m_shownUrl.equals(url, KUrl::CompareWithoutTrailingSlash)) {
+ cancelRequest();
+ m_shownUrl = url;
+ showItemInfo();
+ }
}
-void InfoSidebarPage::requestDelayedItemInfo(const KUrl& url)
+void InfoSidebarPage::setSelection(const KFileItemList& selection)
{
cancelRequest();
-
- if (!url.isEmpty() && !m_multipleSelection) {
- m_urlCandidate = url;
- m_timer->setSingleShot(true);
- m_timer->start(300);
- }
+ m_currentSelection = selection;
+ m_multipleSelection = (m_currentSelection.size() > 1);
+ showItemInfo();
}
-void InfoSidebarPage::requestItemInfo(const KUrl& url)
+void InfoSidebarPage::requestDelayedItemInfo(const KUrl& url)
{
cancelRequest();
if (!url.isEmpty() && !m_multipleSelection) {
- m_shownUrl = url;
- showItemInfo();
+ m_urlCandidate = url;
+ m_timer->setSingleShot(true);
+ m_timer->start(300);
}
}
{
cancelRequest();
- m_multipleSelection = false;
-
- // show the preview...
- DolphinView* view = mainWindow()->activeView();
- const KFileItemList selectedItems = view->selectedItems();
+ KFileItemList selectedItems = m_currentSelection;
KUrl file;
- if (selectedItems.count() > 1) {
- m_multipleSelection = true;
- } else if(selectedItems.count() == 0) {
+ if(selectedItems.count() == 0) {
file = m_shownUrl;
} else {
file = selectedItems[0]->url();
}
}
-void InfoSidebarPage::gotPreview(const KFileItem* /* item */,
+void InfoSidebarPage::gotPreview(const KFileItem* item,
const QPixmap& pixmap)
{
+ Q_UNUSED(item);
if (m_pendingPreview) {
m_preview->setPixmap(pixmap);
m_pendingPreview = false;
void InfoSidebarPage::startService(int index)
{
- DolphinView* view = mainWindow()->activeView();
- if (view->hasSelection()) {
- KUrl::List selectedUrls = view->selectedUrls();
+ if (m_currentSelection.count() > 0) {
// TODO: Use "at()" as soon as executeService is fixed to take a const param (BIC)
- KDEDesktopMimeType::executeService(selectedUrls, m_actionsVector[index]);
+ KDEDesktopMimeType::executeService(m_currentSelection.urlList(), m_actionsVector[index]);
}
else {
// TODO: likewise
}
}
-void InfoSidebarPage::connectToActiveView()
-{
- cancelRequest();
-
- DolphinView* view = mainWindow()->activeView();
- connect(view, SIGNAL(requestItemInfo(const KUrl&)),
- this, SLOT(requestDelayedItemInfo(const KUrl&)));
- connect(view, SIGNAL(urlChanged(const KUrl&)),
- this, SLOT(requestItemInfo(const KUrl&)));
-
- m_shownUrl = view->url();
- showItemInfo();
-}
-
bool InfoSidebarPage::applyBookmark(const KUrl& url)
{
KBookmarkGroup root = DolphinSettings::instance().bookmarkManager()->root();
void InfoSidebarPage::createMetaInfo()
{
beginInfoLines();
- DolphinView* view = mainWindow()->activeView();
- if (!view->hasSelection()) {
+ if(m_currentSelection.size() == 0) {
KFileItem fileItem(S_IFDIR, KFileItem::Unknown, m_shownUrl);
fileItem.refresh();
if ( MetaDataWidget::metaDataAvailable() )
m_metadataWidget->setFile( fileItem.url() );
}
- else if (view->selectedItems().count() == 1) {
- KFileItem* fileItem = view->selectedItems()[0];
+ else if (m_currentSelection.count() == 1) {
+ KFileItem* fileItem = m_currentSelection.at(0);
addInfoLine(i18n("Type:"), fileItem->mimeComment());
QString sizeText(KIO::convertSize(fileItem->size()));
}
else {
if ( MetaDataWidget::metaDataAvailable() )
- m_metadataWidget->setFiles( view->selectedItems().urlList() );
+ m_metadataWidget->setFiles( m_currentSelection.urlList() );
unsigned long int totSize = 0;
- foreach(KFileItem* item, view->selectedItems()) {
+ foreach(KFileItem* item, m_currentSelection) {
totSize += item->size(); //FIXME what to do with directories ? (same with the one-item-selected-code), item->size() does not return the size of the content : not very instinctive for users
}
addInfoLine(i18n("Total size:"), KIO::convertSize(totSize));
// of KFileItems. If no selection is given, a temporary KFileItem
// by the given Url 'url' is created and added to the list.
KFileItem fileItem(S_IFDIR, KFileItem::Unknown, m_shownUrl);
- KFileItemList itemList = mainWindow()->activeView()->selectedItems();
+ KFileItemList itemList = m_currentSelection;
if (itemList.isEmpty()) {
fileItem.refresh();
itemList.append(&fileItem);
class KFileItem;
class QLabel;
class KVBox;
-class Q3Grid;
class PixmapViewer;
class MetaDataWidget;
Q_OBJECT
public:
- explicit InfoSidebarPage(DolphinMainWindow* mainWindow, QWidget* parent = 0);
+ explicit InfoSidebarPage(QWidget* parent = 0);
virtual ~InfoSidebarPage();
-protected:
- /** @see SidebarPage::activeViewChanged() */
- virtual void activeViewChanged();
+public slots:
+ void setUrl(const KUrl& url);
+ void setSelection(const KFileItemList& selection);
private slots:
/**
*/
void requestDelayedItemInfo(const KUrl& url);
- /**
- * Does a request of information for the item of the given Url and
- * provides default actions.
- *
- * @see InfoSidebarPage::showItemInfo()
- */
- void requestItemInfo(const KUrl& url);
-
/**
* Shows the information for the item of the Url which has been provided by
* InfoSidebarPage::requestItemInfo() and provides default actions.
void startService(int index);
private:
- /**
- * Connects to signals from the currently active Dolphin view to get
- * informed about highlighting changes.
- */
- void connectToActiveView();
-
/**
* Checks whether the an Url is repesented by a bookmark. If yes,
* then the bookmark icon and name are shown instead of a preview.
QTimer* m_timer;
KUrl m_shownUrl;
KUrl m_urlCandidate;
+ KFileItemList m_currentSelection;
PixmapViewer* m_preview;
QLabel* m_name;
***************************************************************************/
#include "sidebarpage.h"
-#include "dolphinmainwindow.h"
+#include <QWidget>
+#include <kfileitem.h>
+#include <kurl.h>
-SidebarPage::SidebarPage(DolphinMainWindow* mainWindow, QWidget* parent) :
+SidebarPage::SidebarPage(QWidget* parent) :
QWidget(parent),
- m_mainWindow(mainWindow)
+ m_url(KUrl()),
+ m_currentSelection(KFileItemList())
{
- connect(mainWindow, SIGNAL(activeViewChanged()),
- this, SLOT(activeViewChanged()));
}
SidebarPage::~SidebarPage()
{
}
-void SidebarPage::activeViewChanged()
+void SidebarPage::setUrl(const KUrl& url)
{
+ m_url = url;
}
-DolphinMainWindow* SidebarPage::mainWindow() const {
- return m_mainWindow;
+void SidebarPage::setSelection(const KFileItemList& selection)
+{
+ m_currentSelection = selection;
}
#include "sidebarpage.moc"
#ifndef _SIDEBARPAGE_H_
#define _SIDEBARPAGE_H_
-#include <qwidget.h>
-
-class DolphinMainWindow;
-class Sidebar;
+#include <QWidget>
+#include <kurl.h>
+#include <kfileitem.h>
/**
* @brief Base widget for all pages that can be embedded into the Sidebar.
*
- * TODO
*/
class SidebarPage : public QWidget
{
Q_OBJECT
-
public:
- explicit SidebarPage(DolphinMainWindow* mainwindow, QWidget* parent=0);
+ explicit SidebarPage(QWidget* parent=0);
virtual ~SidebarPage();
-protected slots:
+public slots:
/**
- * Is invoked whenever the active view from Dolphin has been changed.
- * The active view can be retrieved by mainWindow()->activeView();
+ * This is invoked every time the folder being displayed in the
+ * file-management views changes.
*/
- virtual void activeViewChanged();
+ virtual void setUrl(const KUrl& url);
-protected:
- DolphinMainWindow* mainWindow() const;
+ /**
+ * This is invoked to inform the sidebar that the user has selected a new
+ * set of files.
+ */
+ virtual void setSelection(const KFileItemList& selection);
+
+signals:
+ /**
+ * This signal is emited when the sidebar requests an URL-change in the
+ * currently active file-management view. The view is not requested to
+ * accept this change, if it is accepted the sidebar will be informed via
+ * the setUrl() slot.
+ */
+ void changeUrl(const KUrl& url);
-private:
- DolphinMainWindow *m_mainWindow;
+ /**
+ * 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);
+
+ /**
+ * This signal is emitted whenever a drop action on this widget needs the
+ * MainWindow's attention.
+ */
+ void urlsDropped(const KUrl::List& urls, const KUrl& destination);
+
+protected:
+ KUrl m_url;
+ KFileItemList m_currentSelection;
};
#endif // _SIDEBARPAGE_H_
#include <QDropEvent>
#include <QHeaderView>
-SidebarTreeView::SidebarTreeView(DolphinMainWindow* mainWindow,
- QWidget* parent) :
- QTreeView(parent),
- m_mainWindow(mainWindow)
+SidebarTreeView::SidebarTreeView(QWidget* parent) :
+ QTreeView(parent)
{
setAcceptDrops(true);
setUniformRowHeights(true);
#include <kurl.h>
#include <QTreeView>
-class DolphinMainWindow;
-
/**
* @brief Tree view widget which is used for the sidebar panel.
*
Q_OBJECT
public:
- explicit SidebarTreeView(DolphinMainWindow* mainWindow, QWidget* parent = 0);
+ explicit SidebarTreeView(QWidget* parent = 0);
virtual ~SidebarTreeView();
signals:
virtual void dragEnterEvent(QDragEnterEvent* event);
virtual void dropEvent(QDropEvent* event);
-private:
- DolphinMainWindow* m_mainWindow;
};
#endif
--- /dev/null
+/***************************************************************************
+ * 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 <kiconloader.h>
+#include <kmenu.h>
+#include <konqmimedata.h>
+#include <konq_operations.h>
+#include <klocale.h>
+#include <kpropertiesdialog.h>
+
+#include <QApplication>
+#include <QClipboard>
+
+TreeViewContextMenu::TreeViewContextMenu(QWidget* parent,
+ KFileItem* fileInfo) :
+ m_parent(parent),
+ m_fileInfo(fileInfo)
+{
+}
+
+TreeViewContextMenu::~TreeViewContextMenu()
+{
+}
+
+void TreeViewContextMenu::open()
+{
+ Q_ASSERT(m_fileInfo != 0);
+
+ KMenu* popup = new KMenu(m_parent);
+
+ // insert 'Cut', 'Copy' and 'Paste'
+ QAction* cutAction = new QAction(KIcon("edit-cut"), i18n("Cut"), this);
+ connect(cutAction, SIGNAL(triggered()), this, SLOT(cut()));
+
+ QAction* copyAction = new QAction(KIcon("edit-copy"), i18n("Copy"), this);
+ connect(copyAction, SIGNAL(triggered()), this, SLOT(copy()));
+
+ QAction* pasteAction = new QAction(KIcon("edit-paste"), i18n("Paste"), this);
+
+ QClipboard* clipboard = QApplication::clipboard();
+ const QMimeData* mimeData = clipboard->mimeData();
+ const KUrl::List sourceUrls = KUrl::List::fromMimeData(mimeData);
+ pasteAction->setEnabled(sourceUrls.isEmpty());
+ connect(pasteAction, SIGNAL(triggered()), this, SLOT(paste()));
+
+ popup->addAction(cutAction);
+ popup->addAction(copyAction);
+ popup->addAction(pasteAction);
+ popup->addSeparator();
+
+ // insert 'Rename'
+ QAction* renameAction = new QAction(i18n("Rename"), this);
+ connect(renameAction, SIGNAL(triggered()), this, SLOT(rename()));
+ popup->addAction(renameAction);
+
+ // insert 'Move to Trash' and (optionally) 'Delete'
+ const KSharedConfig::Ptr globalConfig = KSharedConfig::openConfig("kdeglobals", KConfig::NoGlobals);
+ const KConfigGroup kdeConfig(globalConfig, "KDE");
+ bool showDeleteCommand = kdeConfig.readEntry("ShowDeleteCommand", false);
+ const KUrl& url = m_fileInfo->url();
+ if (url.isLocalFile()) {
+ QAction* moveToTrashAction = new QAction(KIcon("edit-trash"), i18n("Move To Trash"), this);
+ connect(moveToTrashAction, SIGNAL(triggered()), this, SLOT(moveToTrash()));
+ popup->addAction(moveToTrashAction);
+ }
+ else {
+ showDeleteCommand = true;
+ }
+
+ if (showDeleteCommand) {
+ QAction* deleteAction = new QAction(KIcon("edit-delete"), i18n("Delete"), this);
+ connect(deleteAction, SIGNAL(triggered()), this, SLOT(deleteItem()));
+ popup->addAction(deleteAction);
+ }
+
+ popup->addSeparator();
+
+ // insert 'Properties...' entry
+ QAction* propertiesAction = new QAction(i18n("Properties..."), this);
+ connect(this, SIGNAL(triggered()), this, SLOT(showProperties()));
+ popup->addAction(propertiesAction);
+
+ popup->exec(QCursor::pos());
+ popup->deleteLater();
+}
+
+void TreeViewContextMenu::cut()
+{
+ QMimeData* mimeData = new QMimeData();
+ KUrl::List kdeUrls;
+ kdeUrls.append(m_fileInfo->url());
+ KonqMimeData::populateMimeData(mimeData, kdeUrls, KUrl::List(), true);
+ QApplication::clipboard()->setMimeData(mimeData);
+}
+
+void TreeViewContextMenu::copy()
+{
+ QMimeData* mimeData = new QMimeData();
+ KUrl::List kdeUrls;
+ kdeUrls.append(m_fileInfo->url());
+ KonqMimeData::populateMimeData(mimeData, kdeUrls, KUrl::List(), 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()
+{
+ // TODO
+}
+
+void TreeViewContextMenu::moveToTrash()
+{
+ // TODO
+}
+
+void TreeViewContextMenu::deleteItem()
+{
+ // TODO
+}
+
+void TreeViewContextMenu::showProperties()
+{
+ new KPropertiesDialog(m_fileInfo->url());
+}
+
+#include "treeviewcontextmenu.moc"
--- /dev/null
+/***************************************************************************
+ * 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 TREEVIEWCONTEXTMENU_H
+#define TREEVIEWCONTEXTMENU_H
+
+#include <QObject>
+
+class KMenu;
+class KFileItem;
+class QAction;
+
+/**
+ * @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 parent widget 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(QWidget* parent,
+ 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();
+
+private:
+ QWidget* m_parent;
+ KFileItem* m_fileInfo;
+};
+
+#endif
#include "treeviewsidebarpage.h"
#include "bookmarkselector.h"
-#include "dolphincontextmenu.h"
#include "dolphinmainwindow.h"
#include "dolphinsortfilterproxymodel.h"
#include "dolphinview.h"
#include "sidebartreeview.h"
+#include "treeviewcontextmenu.h"
#include <kdirlister.h>
#include <kdirmodel.h>
// model:
//#define USE_PROXY_MODEL
-TreeViewSidebarPage::TreeViewSidebarPage(DolphinMainWindow* mainWindow,
- QWidget* parent) :
- SidebarPage(mainWindow, parent),
+TreeViewSidebarPage::TreeViewSidebarPage(QWidget* parent) :
+ SidebarPage(parent),
m_dirLister(0),
m_dirModel(0),
m_proxyModel(0),
- m_treeView(0),
- m_selectedUrl()
+ m_treeView(0)
{
- Q_ASSERT(mainWindow != 0);
-
m_dirLister = new KDirLister();
m_dirLister->setDirOnlyMode(true);
m_dirLister->setAutoUpdate(true);
m_proxyModel = new DolphinSortFilterProxyModel(this);
m_proxyModel->setSourceModel(m_dirModel);
- m_treeView = new SidebarTreeView(mainWindow, this);
+ m_treeView = new SidebarTreeView(this);
m_treeView->setModel(m_proxyModel);
m_proxyModel->setSorting(DolphinView::SortByName);
m_proxyModel->setSortOrder(Qt::Ascending);
#else
- m_treeView = new SidebarTreeView(mainWindow, this);
+ m_treeView = new SidebarTreeView(this);
m_treeView->setModel(m_dirModel);
#endif
m_dirLister = 0;
}
-void TreeViewSidebarPage::activeViewChanged()
-{
- connectToActiveView();
-}
-
-void TreeViewSidebarPage::showEvent(QShowEvent* event)
-{
- SidebarPage::showEvent(event);
- connectToActiveView();
-}
-
-void TreeViewSidebarPage::contextMenuEvent(QContextMenuEvent* event)
-{
- SidebarPage::contextMenuEvent(event);
-
- const QModelIndex index = m_treeView->indexAt(event->pos());
- if (!index.isValid()) {
- // only open a context menu above a directory item
- return;
- }
-
-#if defined(USE_PROXY_MODEL)
- const QModelIndex dirModelIndex = m_proxyModel->mapToSource(index);
- KFileItem* item = m_dirModel->itemForIndex(dirModelIndex);
-#else
- KFileItem* item = m_dirModel->itemForIndex(index);
-#endif
-
- mainWindow()->activeView()->clearSelection();
- DolphinContextMenu contextMenu(mainWindow(),
- item,
- m_dirLister->url(),
- DolphinContextMenu::SidebarView);
- contextMenu.open();
-}
-
-void TreeViewSidebarPage::updateSelection(const KUrl& url)
+void TreeViewSidebarPage::setUrl(const KUrl& url)
{
- if (!url.isValid() || (url == m_selectedUrl)) {
+ if (!url.isValid() || (url == m_url)) {
return;
}
- m_selectedUrl = url;
+ m_url = url;
// adjust the root of the tree to the base bookmark
const KUrl baseUrl = BookmarkSelector::baseBookmark(url).url();
parentUrl = parentUrl.upUrl();
}
}
+
+}
+
+void TreeViewSidebarPage::showEvent(QShowEvent* event)
+{
+ SidebarPage::showEvent(event);
+}
+
+void TreeViewSidebarPage::contextMenuEvent(QContextMenuEvent* event)
+{
+ SidebarPage::contextMenuEvent(event);
+
+ const QModelIndex index = m_treeView->indexAt(event->pos());
+ if (!index.isValid()) {
+ // only open a context menu above a directory item
+ return;
+ }
+
+#if defined(USE_PROXY_MODEL)
+ const QModelIndex dirModelIndex = m_proxyModel->mapToSource(index);
+ KFileItem* item = m_dirModel->itemForIndex(dirModelIndex);
+#else
+ KFileItem* item = m_dirModel->itemForIndex(index);
+#endif
+
+ emit changeSelection(KFileItemList());
+ TreeViewContextMenu contextMenu(this, item);
+ contextMenu.open();
}
void TreeViewSidebarPage::expandSelectionParent()
this, SLOT(expandSelectionParent()));
// expand the parent folder of the selected item
- KUrl parentUrl = m_selectedUrl.upUrl();
+ KUrl parentUrl = m_url.upUrl();
if (!m_dirLister->url().isParentOf(parentUrl)) {
return;
}
#endif
// select the item and assure that the item is visible
- index = m_dirModel->indexForUrl(m_selectedUrl);
+ index = m_dirModel->indexForUrl(m_url);
if (index.isValid()) {
#if defined(USE_PROXY_MODEL)
proxyIndex = m_proxyModel->mapFromSource(index);
#endif
if (item != 0) {
const KUrl& url = item->url();
- mainWindow()->activeView()->setUrl(url);
+ emit changeUrl(url);
}
}
#endif
Q_ASSERT(item != 0);
if (item->isDir()) {
- mainWindow()->dropUrls(urls, item->url());
+ emit urlsDropped(urls, item->url());
}
}
}
-void TreeViewSidebarPage::connectToActiveView()
-{
- const QWidget* parent = parentWidget();
- if ((parent == 0) || parent->isHidden()) {
- return;
- }
-
- const DolphinView* view = mainWindow()->activeView();
- const KUrl& url = view->url();
-
- connect(view, SIGNAL(urlChanged(const KUrl&)),
- this, SLOT(updateSelection(const KUrl&)));
-
- updateSelection(url);
-}
-
#include "treeviewsidebarpage.moc"
Q_OBJECT
public:
- TreeViewSidebarPage(DolphinMainWindow* mainWindow, QWidget* parent = 0);
+ TreeViewSidebarPage(QWidget* parent = 0);
virtual ~TreeViewSidebarPage();
-protected:
- /** @see SidebarPage::activeViewChanged() */
- virtual void activeViewChanged();
+public slots:
+ /**
+ * Changes the current selection inside the tree to \a url.
+ */
+ void setUrl(const KUrl& url);
+protected:
/** @see QWidget::showEvent() */
virtual void showEvent(QShowEvent* event);
virtual void contextMenuEvent(QContextMenuEvent* event);
private slots:
- /**
- * Updates the current selection inside the tree to
- * \a url.
- */
- void updateSelection(const KUrl& url);
-
/**
* Expands the tree in a way that the item with the URL m_selectedUrl
* gets visible. Is called by TreeViewSidebarPage::updateSelection()
void dropUrls(const KUrl::List& urls,
const QModelIndex& index);
-private:
- /**
- * Connects to signals from the currently active Dolphin view to get
- * informed about highlighting changes.
- */
- void connectToActiveView();
-
private:
KDirLister* m_dirLister;
KDirModel* m_dirModel;
DolphinSortFilterProxyModel* m_proxyModel;
SidebarTreeView* m_treeView;
- KUrl m_selectedUrl;
};
#endif // TREEVIEWSIDEBARPAGE_H
const bool clipped = isTextClipped();
const int align = clipped ? Qt::AlignVCenter : Qt::AlignCenter;
- painter.drawText(QRect(0, 0, textWidth, buttonHeight), align, text());
-
+ const QRect textRect(0, 0, textWidth, buttonHeight);
if (clipped) {
- // Blend the right area of the text with the background, as the
- // text is clipped.
- // TODO: use alpha blending in Qt4 instead of drawing the text that often
- const int blendSteps = 16;
-
- QColor blendColor(backgroundColor);
- const int redInc = (foregroundColor.red() - backgroundColor.red()) / blendSteps;
- const int greenInc = (foregroundColor.green() - backgroundColor.green()) / blendSteps;
- const int blueInc = (foregroundColor.blue() - backgroundColor.blue()) / blendSteps;
- for (int i = 0; i < blendSteps; ++i) {
- painter.setClipRect(QRect(textWidth - i, 0, 1, buttonHeight));
- painter.setPen(blendColor);
- painter.drawText(QRect(0, 0, textWidth, buttonHeight), align, text());
-
- blendColor.setRgb(blendColor.red() + redInc,
- blendColor.green() + greenInc,
- blendColor.blue() + blueInc);
- }
+ QLinearGradient gradient(textRect.topLeft(), textRect.topRight());
+ gradient.setColorAt(0.8, foregroundColor);
+ gradient.setColorAt(1.0, backgroundColor);
+
+ QPen pen;
+ pen.setBrush(QBrush(gradient));
+ painter.setPen(pen);
+ painter.drawText(textRect, align, text());
+ }
+ else {
+ painter.drawText(textRect, align, text());
}
}