mirror of
https://invent.kde.org/system/dolphin
synced 2024-09-19 16:31:21 +00:00
Places Panel: Allow showing of hidden items
This commit is contained in:
parent
f158bf097a
commit
aacf20282d
|
@ -922,6 +922,13 @@ void KItemListView::slotItemsInserted(const KItemRangeList& itemRanges)
|
|||
}
|
||||
}
|
||||
|
||||
// In case if items of the same group have been inserted before an item that
|
||||
// currently represents the first item of the group, the group header of
|
||||
// this item must be removed.
|
||||
if (m_grouped && index + count < m_model->count()) {
|
||||
updateGroupHeaderForWidget(m_visibleItems.value(index + count));
|
||||
}
|
||||
|
||||
if (m_model->count() == count && m_activeTransactions == 0) {
|
||||
// Check whether a scrollbar is required to show the inserted items. In this case
|
||||
// the size of the layouter will be decreased before calling doLayout(): This prevents
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "kstandarditem.h"
|
||||
|
||||
#include <KDebug>
|
||||
#include "kstandarditemmodel.h"
|
||||
|
||||
KStandardItem::KStandardItem(KStandardItem* parent) :
|
||||
m_parent(parent),
|
||||
|
@ -62,7 +63,7 @@ KStandardItem::~KStandardItem()
|
|||
|
||||
void KStandardItem::setText(const QString& text)
|
||||
{
|
||||
m_data.insert("text", text);
|
||||
setDataValue("text", text);
|
||||
}
|
||||
|
||||
QString KStandardItem::text() const
|
||||
|
@ -72,7 +73,7 @@ QString KStandardItem::text() const
|
|||
|
||||
void KStandardItem::setIcon(const QIcon& icon)
|
||||
{
|
||||
m_data.insert("iconName", icon.name());
|
||||
setDataValue("iconName", icon.name());
|
||||
}
|
||||
|
||||
QIcon KStandardItem::icon() const
|
||||
|
@ -82,7 +83,7 @@ QIcon KStandardItem::icon() const
|
|||
|
||||
void KStandardItem::setGroup(const QString& group)
|
||||
{
|
||||
m_data.insert("group", group);
|
||||
setDataValue("group", group);
|
||||
}
|
||||
|
||||
QString KStandardItem::group() const
|
||||
|
@ -93,6 +94,12 @@ QString KStandardItem::group() const
|
|||
void KStandardItem::setDataValue(const QByteArray& role, const QVariant& value)
|
||||
{
|
||||
m_data.insert(role, value);
|
||||
if (m_model) {
|
||||
const int index = m_model->index(this);
|
||||
QSet<QByteArray> changedRoles;
|
||||
changedRoles.insert(role);
|
||||
emit m_model->itemsChanged(KItemRangeList() << KItemRange(index, 1), changedRoles);
|
||||
}
|
||||
}
|
||||
|
||||
QVariant KStandardItem::dataValue(const QByteArray& role) const
|
||||
|
|
|
@ -259,7 +259,7 @@ void KStandardItemListWidget::paint(QPainter* painter, const QStyleOptionGraphic
|
|||
}
|
||||
|
||||
painter->setFont(itemListStyleOption.font);
|
||||
painter->setPen(textColor());
|
||||
painter->setPen(m_isHidden ? m_additionalInfoTextColor : textColor());
|
||||
const TextInfo* textInfo = m_textInfo.value("text");
|
||||
painter->drawStaticText(textInfo->pos, textInfo->staticText);
|
||||
|
||||
|
@ -480,12 +480,15 @@ void KStandardItemListWidget::dataChanged(const QHash<QByteArray, QVariant>& cur
|
|||
QSet<QByteArray> dirtyRoles;
|
||||
if (roles.isEmpty()) {
|
||||
dirtyRoles = visibleRoles().toSet();
|
||||
dirtyRoles.insert("iconPixmap");
|
||||
dirtyRoles.insert("iconName");
|
||||
} else {
|
||||
dirtyRoles = roles;
|
||||
}
|
||||
|
||||
// The icon-state might depend from other roles and hence is
|
||||
// marked as dirty whenever a role has been changed
|
||||
dirtyRoles.insert("iconPixmap");
|
||||
dirtyRoles.insert("iconName");
|
||||
|
||||
QSetIterator<QByteArray> it(dirtyRoles);
|
||||
while (it.hasNext()) {
|
||||
const QByteArray& role = it.next();
|
||||
|
|
|
@ -38,7 +38,7 @@ KStandardItemModel::~KStandardItemModel()
|
|||
|
||||
void KStandardItemModel::insertItem(int index, KStandardItem* item)
|
||||
{
|
||||
if (item && !m_indexesForItems.contains(item) && !item->m_model) {
|
||||
if (item && !m_indexesForItems.contains(item)) {
|
||||
item->m_model = this;
|
||||
m_items.insert(index, item);
|
||||
m_indexesForItems.insert(item, index);
|
||||
|
@ -51,7 +51,7 @@ void KStandardItemModel::insertItem(int index, KStandardItem* item)
|
|||
|
||||
void KStandardItemModel::replaceItem(int index, KStandardItem* item)
|
||||
{
|
||||
if (item && index >= 0 && index < count() && !item->m_model) {
|
||||
if (item && index >= 0 && index < count()) {
|
||||
item->m_model = this;
|
||||
|
||||
QSet<QByteArray> changedRoles;
|
||||
|
|
|
@ -98,6 +98,8 @@ protected:
|
|||
private:
|
||||
QList<KStandardItem*> m_items;
|
||||
QHash<const KStandardItem*, int> m_indexesForItems;
|
||||
|
||||
friend class KStandardItem;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -73,10 +73,16 @@ PlacesItemModel::~PlacesItemModel()
|
|||
|
||||
int PlacesItemModel::hiddenCount() const
|
||||
{
|
||||
int modelIndex = 0;
|
||||
int itemCount = 0;
|
||||
foreach (const KStandardItem* item, m_hiddenItems) {
|
||||
if (item) {
|
||||
foreach (const KStandardItem* hiddenItem, m_hiddenItems) {
|
||||
if (hiddenItem) {
|
||||
++itemCount;
|
||||
} else {
|
||||
if (item(modelIndex)->dataValue("isHidden").toBool()) {
|
||||
++itemCount;
|
||||
}
|
||||
++modelIndex;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -108,9 +114,31 @@ bool PlacesItemModel::isItemHidden(int index) const
|
|||
|
||||
void PlacesItemModel::setHiddenItemsShown(bool show)
|
||||
{
|
||||
if (m_hiddenItemsShown != show) {
|
||||
m_hiddenItemsShown = show;
|
||||
if (m_hiddenItemsShown == show) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_hiddenItemsShown = show;
|
||||
|
||||
if (show) {
|
||||
int modelIndex = 0;
|
||||
for (int hiddenIndex = 0; hiddenIndex < m_hiddenItems.count(); ++hiddenIndex) {
|
||||
if (m_hiddenItems[hiddenIndex]) {
|
||||
KStandardItem* visibleItem = new KStandardItem(*m_hiddenItems[hiddenIndex]);
|
||||
delete m_hiddenItems[hiddenIndex];
|
||||
m_hiddenItems.removeAt(hiddenIndex);
|
||||
insertItem(modelIndex, visibleItem);
|
||||
Q_ASSERT(!m_hiddenItems[hiddenIndex]);
|
||||
}
|
||||
++modelIndex;
|
||||
}
|
||||
} else {
|
||||
|
||||
}
|
||||
#ifdef PLACESITEMMODEL_DEBUG
|
||||
kDebug() << "Changed visibility of hidden items";
|
||||
showModelState();
|
||||
#endif
|
||||
}
|
||||
|
||||
bool PlacesItemModel::hiddenItemsShown() const
|
||||
|
@ -175,11 +203,24 @@ QAction* PlacesItemModel::tearDownAction(int index) const
|
|||
|
||||
void PlacesItemModel::onItemInserted(int index)
|
||||
{
|
||||
if (index == count() - 1) {
|
||||
m_hiddenItems.append(0);
|
||||
} else {
|
||||
m_hiddenItems.insert(hiddenIndex(index), 0);
|
||||
int modelIndex = 0;
|
||||
int hiddenIndex = 0;
|
||||
while (hiddenIndex < m_hiddenItems.count()) {
|
||||
if (!m_hiddenItems[hiddenIndex]) {
|
||||
++modelIndex;
|
||||
if (modelIndex + 1 == index) {
|
||||
++hiddenIndex;
|
||||
break;
|
||||
}
|
||||
}
|
||||
++hiddenIndex;
|
||||
}
|
||||
m_hiddenItems.insert(hiddenIndex, 0);
|
||||
|
||||
#ifdef PLACESITEMMODEL_DEBUG
|
||||
kDebug() << "Inserted item" << index;
|
||||
showModelState();
|
||||
#endif
|
||||
}
|
||||
|
||||
void PlacesItemModel::onItemRemoved(int index)
|
||||
|
|
|
@ -218,14 +218,26 @@ void PlacesPanel::slotViewContextMenuRequested(const QPointF& pos)
|
|||
KMenu menu(this);
|
||||
|
||||
QAction* addAction = menu.addAction(KIcon("document-new"), i18nc("@item:inmenu", "Add Entry..."));
|
||||
|
||||
QAction* showAllAction = 0;
|
||||
if (m_model->hiddenCount() > 0) {
|
||||
showAllAction = menu.addAction(i18nc("@item:inmenu", "Show All Entries"));
|
||||
showAllAction->setCheckable(true);
|
||||
showAllAction->setChecked(m_model->hiddenItemsShown());
|
||||
}
|
||||
|
||||
menu.addSeparator();
|
||||
foreach (QAction* action, customContextMenuActions()) {
|
||||
menu.addAction(action);
|
||||
}
|
||||
|
||||
QAction* action = menu.exec(pos.toPoint());
|
||||
if (action == addAction) {
|
||||
addEntry();
|
||||
if (action) {
|
||||
if (action == addAction) {
|
||||
addEntry();
|
||||
} else if (action == showAllAction) {
|
||||
m_model->setHiddenItemsShown(showAllAction->isChecked());
|
||||
}
|
||||
}
|
||||
|
||||
selectClosestItem();
|
||||
|
|
Loading…
Reference in a new issue