Allow showing additional information like type, size and date in parallel for the icons view (thanks to Fredrik for the extension of KFileItemDelegate!).

svn path=/trunk/KDE/kdebase/apps/; revision=720283
This commit is contained in:
Peter Penz 2007-10-02 22:04:36 +00:00
parent ba150e5735
commit 3c1c185400
12 changed files with 149 additions and 117 deletions

View file

@ -52,7 +52,7 @@
<entry name="AdditionalInfo" type="Int">
<label context="@label">Additional information</label>
<default code="true">KFileItemDelegate::NoInformation</default>
<default>0</default>
</entry>
<entry name="Timestamp" type="DateTime" >

View file

@ -24,9 +24,10 @@
DolphinController::DolphinController(QObject* parent) :
QObject(parent),
m_showPreview(false),
m_showAdditionalInfo(false),
m_zoomInPossible(false),
m_zoomOutPossible(false)
m_zoomOutPossible(false),
m_additionalInfoCount(0),
m_url()
{
}
@ -80,11 +81,11 @@ void DolphinController::setShowPreview(bool show)
}
}
void DolphinController::setShowAdditionalInfo(bool show)
void DolphinController::setAdditionalInfoCount(int count)
{
if (m_showAdditionalInfo != show) {
m_showAdditionalInfo = show;
emit showAdditionalInfoChanged(show);
if (m_additionalInfoCount != count) {
m_additionalInfoCount = count;
emit additionalInfoCountChanged(count);
}
}

View file

@ -77,8 +77,8 @@ public:
void setShowPreview(bool show);
bool showPreview() const;
void setShowAdditionalInfo(bool show);
bool showAdditionalInfo() const;
void setAdditionalInfoCount(int count);
bool additionalInfoCount() const;
void triggerZoomIn();
void setZoomInPossible(bool possible);
@ -156,10 +156,10 @@ signals:
void showPreviewChanged(bool show);
/**
* Is emitted if the state for showing additional info has been
* changed to \a show.
* Is emitted if the number of additional informations has been
* changed to \a count.
*/
void showAdditionalInfoChanged(bool show);
void additionalInfoCountChanged(int count);
/**
* Is emitted if the item with the index \a index should be triggered.
@ -188,9 +188,9 @@ signals:
private:
bool m_showPreview;
bool m_showAdditionalInfo;
bool m_zoomInPossible;
bool m_zoomOutPossible;
int m_additionalInfoCount;
KUrl m_url;
};
@ -204,9 +204,9 @@ inline bool DolphinController::showPreview() const
return m_showPreview;
}
inline bool DolphinController::showAdditionalInfo() const
inline bool DolphinController::additionalInfoCount() const
{
return m_showAdditionalInfo;
return m_additionalInfoCount;
}
inline void DolphinController::setZoomInPossible(bool possible)

View file

@ -64,8 +64,8 @@ DolphinIconsView::DolphinIconsView(QWidget* parent, DolphinController* controlle
controller, SLOT(emitViewportEntered()));
connect(controller, SIGNAL(showPreviewChanged(bool)),
this, SLOT(slotShowPreviewChanged(bool)));
connect(controller, SIGNAL(showAdditionalInfoChanged(bool)),
this, SLOT(slotShowAdditionalInfoChanged(bool)));
connect(controller, SIGNAL(additionalInfoCountChanged(int)),
this, SLOT(slotAdditionalInfoCountChanged(int)));
connect(controller, SIGNAL(zoomIn()),
this, SLOT(zoomIn()));
connect(controller, SIGNAL(zoomOut()),
@ -84,7 +84,7 @@ DolphinIconsView::DolphinIconsView(QWidget* parent, DolphinController* controlle
m_viewOptions.font = font;
setWordWrap(settings->numberOfTextlines() > 1);
updateGridSize(controller->showPreview(), controller->showAdditionalInfo());
updateGridSize(controller->showPreview(), controller->additionalInfoCount());
if (settings->arrangement() == QListView::TopToBottom) {
setFlow(QListView::LeftToRight);
@ -230,12 +230,12 @@ void DolphinIconsView::keyPressEvent(QKeyEvent* event)
void DolphinIconsView::slotShowPreviewChanged(bool showPreview)
{
updateGridSize(showPreview, m_controller->showAdditionalInfo());
updateGridSize(showPreview, m_controller->additionalInfoCount());
}
void DolphinIconsView::slotShowAdditionalInfoChanged(bool showAdditionalInfo)
void DolphinIconsView::slotAdditionalInfoCountChanged(int count)
{
updateGridSize(m_controller->showPreview(), showAdditionalInfo);
updateGridSize(m_controller->showPreview(), count);
}
void DolphinIconsView::zoomIn()
@ -264,7 +264,7 @@ void DolphinIconsView::zoomIn()
settings->setItemWidth(settings->itemWidth() + diff);
settings->setItemHeight(settings->itemHeight() + diff);
updateGridSize(showPreview, m_controller->showAdditionalInfo());
updateGridSize(showPreview, m_controller->additionalInfoCount());
}
}
@ -295,7 +295,7 @@ void DolphinIconsView::zoomOut()
settings->setItemWidth(settings->itemWidth() - diff);
settings->setItemHeight(settings->itemHeight() - diff);
updateGridSize(showPreview, m_controller->showAdditionalInfo());
updateGridSize(showPreview, m_controller->additionalInfoCount());
}
}
@ -341,7 +341,7 @@ int DolphinIconsView::decreasedIconSize(int size) const
return decSize;
}
void DolphinIconsView::updateGridSize(bool showPreview, bool showAdditionalInfo)
void DolphinIconsView::updateGridSize(bool showPreview, int additionalInfoCount)
{
const IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings();
Q_ASSERT(settings != 0);
@ -360,9 +360,8 @@ void DolphinIconsView::updateGridSize(bool showPreview, bool showAdditionalInfo)
size = previewSize;
}
if (showAdditionalInfo) {
itemHeight += m_viewOptions.font.pointSize() * 2;
}
Q_ASSERT(additionalInfoCount >= 0);
itemHeight += additionalInfoCount * m_viewOptions.font.pointSize() * 2;
if (settings->arrangement() == QListView::TopToBottom) {
// The decoration width indirectly defines the maximum

View file

@ -60,7 +60,7 @@ protected:
private slots:
void slotShowPreviewChanged(bool show);
void slotShowAdditionalInfoChanged(bool show);
void slotAdditionalInfoCountChanged(int count);
void zoomIn();
void zoomOut();
@ -76,9 +76,9 @@ private:
/**
* Updates the size of the grid depending on the state
* of \a showPreview and \a showAdditionalInfo.
* of \a showPreview and \a additionalInfoCount.
*/
void updateGridSize(bool showPreview, bool showAdditionalInfo);
void updateGridSize(bool showPreview, int additionalInfoCount);
private:
DolphinController* m_controller;

View file

@ -326,33 +326,35 @@ void DolphinMainWindow::slotSortOrderChanged(Qt::SortOrder order)
void DolphinMainWindow::slotAdditionalInfoChanged(KFileItemDelegate::InformationList list)
{
QAction* action = 0;
KFileItemDelegate::Information info = list.isEmpty() ? KFileItemDelegate::NoInformation : list.first();
QAction* showMimeInfo = actionCollection()->action("show_mime_info");
QAction* showSizeInfo = actionCollection()->action("show_size_info");
QAction* showDateInfo = actionCollection()->action("show_date_info");
switch (info) {
case KFileItemDelegate::FriendlyMimeType:
action = actionCollection()->action("show_mime_info");
break;
case KFileItemDelegate::Size:
action = actionCollection()->action("show_size_info");
break;
case KFileItemDelegate::ModificationTime:
action = actionCollection()->action("show_date_info");
break;
case KFileItemDelegate::NoInformation:
default:
action = actionCollection()->action("clear_info");
break;
}
showMimeInfo->setChecked(false);
showSizeInfo->setChecked(false);
showDateInfo->setChecked(false);
if (action != 0) {
KToggleAction* toggleAction = static_cast<KToggleAction*>(action);
toggleAction->setChecked(true);
const DolphinView* view = m_activeViewContainer->view();
// currently only the icons view supports additional information
const bool enable = (view->mode() == DolphinView::IconsView);
showMimeInfo->setEnabled(enable);
showSizeInfo->setEnabled(enable);
showDateInfo->setEnabled(enable);
QActionGroup* group = toggleAction->actionGroup();
Q_ASSERT(group != 0);
const DolphinView* view = m_activeViewContainer->view();
group->setEnabled(view->mode() == DolphinView::IconsView);
foreach (KFileItemDelegate::Information info, list) {
switch (info) {
case KFileItemDelegate::FriendlyMimeType:
showMimeInfo->setChecked(true);
break;
case KFileItemDelegate::Size:
showSizeInfo->setChecked(true);
break;
case KFileItemDelegate::ModificationTime:
showDateInfo->setChecked(true);
break;
default:
break;
}
}
}
@ -776,27 +778,19 @@ void DolphinMainWindow::toggleSortCategorization()
view->setCategorizedSorting(!categorizedSorting);
}
void DolphinMainWindow::clearInfo()
void DolphinMainWindow::toggleMimeInfo()
{
m_activeViewContainer->view()->setAdditionalInfo(KFileItemDelegate::NoInformation);
toggleAdditionalInfo("show_mime_info", KFileItemDelegate::FriendlyMimeType);
}
void DolphinMainWindow::showMimeInfo()
void DolphinMainWindow::toggleSizeInfo()
{
clearStatusBar();
m_activeViewContainer->view()->setAdditionalInfo(KFileItemDelegate::FriendlyMimeType);
toggleAdditionalInfo("show_size_info", KFileItemDelegate::Size);
}
void DolphinMainWindow::showSizeInfo()
void DolphinMainWindow::toggleDateInfo()
{
clearStatusBar();
m_activeViewContainer->view()->setAdditionalInfo(KFileItemDelegate::Size);
}
void DolphinMainWindow::showDateInfo()
{
clearStatusBar();
m_activeViewContainer->view()->setAdditionalInfo(KFileItemDelegate::ModificationTime);
toggleAdditionalInfo("show_date_info", KFileItemDelegate::ModificationTime);
}
void DolphinMainWindow::toggleSplitView()
@ -1245,27 +1239,17 @@ void DolphinMainWindow::setupActions()
showInGroups->setText(i18nc("@action:inmenu View", "Show in Groups"));
connect(showInGroups, SIGNAL(triggered()), this, SLOT(toggleSortCategorization()));
KToggleAction* clearInfo = actionCollection()->add<KToggleAction>("clear_info");
clearInfo->setText(i18nc("@action:inmenu Additional information", "No Information"));
connect(clearInfo, SIGNAL(triggered()), this, SLOT(clearInfo()));
KToggleAction* showMimeInfo = actionCollection()->add<KToggleAction>("show_mime_info");
showMimeInfo->setText(i18nc("@action:inmenu Additional information", "Type"));
connect(showMimeInfo, SIGNAL(triggered()), this, SLOT(showMimeInfo()));
connect(showMimeInfo, SIGNAL(triggered()), this, SLOT(toggleMimeInfo()));
KToggleAction* showSizeInfo = actionCollection()->add<KToggleAction>("show_size_info");
showSizeInfo->setText(i18nc("@action:inmenu Additional information", "Size"));
connect(showSizeInfo, SIGNAL(triggered()), this, SLOT(showSizeInfo()));
connect(showSizeInfo, SIGNAL(triggered()), this, SLOT(toggleSizeInfo()));
KToggleAction* showDateInfo = actionCollection()->add<KToggleAction>("show_date_info");
showDateInfo->setText(i18nc("@action:inmenu Additional information", "Date"));
connect(showDateInfo, SIGNAL(triggered()), this, SLOT(showDateInfo()));
QActionGroup* infoGroup = new QActionGroup(this);
infoGroup->addAction(clearInfo);
infoGroup->addAction(showMimeInfo);
infoGroup->addAction(showSizeInfo);
infoGroup->addAction(showDateInfo);
connect(showDateInfo, SIGNAL(triggered()), this, SLOT(toggleDateInfo()));
KToggleAction* showPreview = actionCollection()->add<KToggleAction>("show_preview");
showPreview->setText(i18nc("@action:intoolbar", "Preview"));
@ -1612,6 +1596,28 @@ void DolphinMainWindow::updateSplitAction()
}
}
void DolphinMainWindow::toggleAdditionalInfo(const char* actionName,
KFileItemDelegate::Information info)
{
clearStatusBar();
DolphinView* view = m_activeViewContainer->view();
KFileItemDelegate::InformationList list = view->additionalInfo();
const bool show = actionCollection()->action(actionName)->isChecked();
const int index = list.indexOf(info);
const bool containsInfo = (index >= 0);
if (show && !containsInfo) {
list.append(info);
view->setAdditionalInfo(list);
} else if (!show && containsInfo) {
list.removeAt(index);
view->setAdditionalInfo(list);
Q_ASSERT(list.indexOf(info) < 0);
}
}
DolphinMainWindow::UndoUiInterface::UndoUiInterface(DolphinMainWindow* mainWin) :
KonqUndoManager::UiInterface(mainWin),
m_mainWin(mainWin)

View file

@ -27,9 +27,10 @@
#include <config-nepomuk.h>
#include <kxmlguiwindow.h>
#include <ksortablelist.h>
#include <kfileitemdelegate.h>
#include <konq_undo.h>
#include <ksortablelist.h>
#include <kxmlguiwindow.h>
#include <QtCore/QList>
@ -292,20 +293,14 @@ private slots:
/** Switches between sorting by categories or not. */
void toggleSortCategorization();
/**
* Clears any additional information for an item except for the
* name and the icon.
*/
void clearInfo();
/** Switches between showing the MIME type as additional information for the item or not. */
void toggleMimeInfo();
/** Shows the MIME type as additional information for the item. */
void showMimeInfo();
/** Switches between showing the size as additional information for the item or not. */
void toggleSizeInfo();
/** Shows the size as additional information for the item. */
void showSizeInfo();
/** Shows the date as additional information for the item. */
void showDateInfo();
/** Switchtes between showing the date as additional information for the item or not. */
void toggleDateInfo();
/**
* Switches between one and two views:
@ -463,6 +458,14 @@ private:
*/
void updateSplitAction();
/**
* Helper method for the slots toggleDateInfo(), toggleSizeInfo()
* and toggleMimeInfo(). Applies \a info dependent from the current
* checked state of the action \a actionName to the file item delegate.
*/
void toggleAdditionalInfo(const char* actionName,
KFileItemDelegate::Information info);
private:
/**
* DolphinMainWindow supports up to two views beside each other.

View file

@ -38,7 +38,6 @@
</Menu>
<Menu name="additional_info">
<text context="@title:menu">Additional Information</text>
<Action name="clear_info" />
<Action name="show_mime_info" />
<Action name="show_size_info" />
<Action name="show_date_info" />

View file

@ -412,22 +412,13 @@ void DolphinView::setAdditionalInfo(KFileItemDelegate::InformationList info)
ViewProperties props(viewPropsUrl);
props.setAdditionalInfo(info);
m_controller->setShowAdditionalInfo(!info.isEmpty());
m_controller->setAdditionalInfoCount(info.count());
m_fileItemDelegate->setShowInformation(info);
emit additionalInfoChanged(info);
startDirLister(viewPropsUrl, true);
}
void DolphinView::setAdditionalInfo(KFileItemDelegate::Information info)
{
KFileItemDelegate::InformationList list;
if (info != KFileItemDelegate::NoInformation)
list << info;
setAdditionalInfo(list);
}
KFileItemDelegate::InformationList DolphinView::additionalInfo() const
{
return m_fileItemDelegate->showInformation();
@ -658,7 +649,7 @@ void DolphinView::applyViewProperties(const KUrl& url)
KFileItemDelegate::InformationList info = props.additionalInfo();
if (info != m_fileItemDelegate->showInformation()) {
m_controller->setShowAdditionalInfo(!info.isEmpty());
m_controller->setAdditionalInfoCount(info.count());
m_fileItemDelegate->setShowInformation(info);
emit additionalInfoChanged(info);
}
@ -807,6 +798,11 @@ void DolphinView::clearHoverInformation()
void DolphinView::createView()
{
KFileItemDelegate::InformationList infoList;
if (m_fileItemDelegate != 0) {
infoList = m_fileItemDelegate->showInformation();
}
// delete current view
QAbstractItemView* view = itemView();
if (view != 0) {
@ -846,6 +842,7 @@ void DolphinView::createView()
Q_ASSERT(view != 0);
m_fileItemDelegate = new KFileItemDelegate(view);
m_fileItemDelegate->setShowInformation(infoList);
view->setItemDelegate(m_fileItemDelegate);
view->setModel(m_proxyModel);

View file

@ -281,9 +281,6 @@ public:
/** Sets the additional information which should be shown for the items. */
void setAdditionalInfo(KFileItemDelegate::InformationList info);
/** Sets the additional information which should be shown for the items. */
void setAdditionalInfo(KFileItemDelegate::Information info);
/** Returns the additional information which should be shown for the items. */
KFileItemDelegate::InformationList additionalInfo() const;

View file

@ -199,8 +199,22 @@ Qt::SortOrder ViewProperties::sortOrder() const
void ViewProperties::setAdditionalInfo(KFileItemDelegate::InformationList list)
{
KFileItemDelegate::Information info = list.isEmpty() ?
KFileItemDelegate::NoInformation : list.first();
int info = NoInfo;
foreach (KFileItemDelegate::Information currentInfo, list) {
switch (currentInfo) {
case KFileItemDelegate::FriendlyMimeType:
info = info | TypeInfo;
break;
case KFileItemDelegate::Size:
info = info | SizeInfo;
break;
case KFileItemDelegate::ModificationTime:
info = info | DateInfo;
break;
default:
break;
}
}
if (m_node->additionalInfo() != info) {
m_node->setAdditionalInfo(info);
@ -210,12 +224,20 @@ void ViewProperties::setAdditionalInfo(KFileItemDelegate::InformationList list)
KFileItemDelegate::InformationList ViewProperties::additionalInfo() const
{
KFileItemDelegate::Information info = static_cast<KFileItemDelegate::Information>(m_node->additionalInfo());
const int info = m_node->additionalInfo();
if (info != KFileItemDelegate::NoInformation)
return KFileItemDelegate::InformationList() << info;
else
return KFileItemDelegate::InformationList();
KFileItemDelegate::InformationList list;
if (info & TypeInfo) {
list.append(KFileItemDelegate::FriendlyMimeType);
}
if (info & SizeInfo) {
list.append(KFileItemDelegate::Size);
}
if (info & DateInfo) {
list.append(KFileItemDelegate::ModificationTime);
}
return list;
}

View file

@ -120,6 +120,14 @@ private:
Q_DISABLE_COPY(ViewProperties)
private:
enum AdditionalInfoValues
{
NoInfo = 0,
TypeInfo = 1,
SizeInfo = 2,
DateInfo = 4
};
bool m_changedProps;
bool m_autoSave;
QString m_filepath;