outline-filter.diff (5,293 bytes)
Index: scribus/outlinepalette.cpp
===================================================================
--- scribus/outlinepalette.cpp (revision 12370)
+++ scribus/outlinepalette.cpp (working copy)
@@ -10,6 +10,9 @@
#include <QHelpEvent>
#include <QImage>
#include <QLabel>
+#include <QLineEdit>
+#include <QGridLayout>
+#include <QShortcut>
#include <QLayout>
#include <QList>
#include <QMenu>
@@ -131,14 +134,16 @@
OutlinePalette::OutlinePalette( QWidget* parent) : ScrPaletteBase( parent, "Tree", false, 0 )
{
- resize( 220, 240 );
setMinimumSize( QSize( 220, 240 ) );
setMaximumSize( QSize( 800, 600 ) );
+ filterEdit = new QLineEdit;
+ filterEdit->setToolTip( tr("Enter a keyword or regular expression to filter the outline.") );
+ QShortcut* filterShortcut = new QShortcut( QKeySequence( tr( "Ctrl+f", "Filter the Outline using a keyword" ) ), this );
+ filterLabel = new QLabel( tr("Filter:") );
+ filterLabel->setBuddy( filterEdit );
+
reportDisplay = new OutlineWidget( this );
-
- reportDisplay->setGeometry( QRect( 0, 0, 220, 240 ) );
- reportDisplay->setMinimumSize( QSize( 220, 240 ) );
reportDisplay->setRootIsDecorated( true );
reportDisplay->setColumnCount(1);
reportDisplay->setHeaderLabel( tr("Element"));
@@ -147,6 +152,14 @@
reportDisplay->setSortingEnabled(false);
reportDisplay->setSelectionMode(QAbstractItemView::ExtendedSelection);
reportDisplay->setContextMenuPolicy(Qt::CustomContextMenu);
+
+ QGridLayout* layout = new QGridLayout;
+ layout->addWidget( filterLabel, 0, 0 );
+ layout->addWidget( filterEdit, 0, 1 );
+ layout->addWidget( reportDisplay, 1, 0, 1, 2 );
+ layout->setContentsMargins( 3, 3, 3, 3);
+ setLayout( layout );
+
unsetDoc();
imageIcon = loadIcon("22/insert-image.png");
latexIcon = loadIcon("22/insert-latex.png");
@@ -172,6 +185,8 @@
connect(reportDisplay, SIGNAL(customContextMenuRequested (const QPoint &)), this, SLOT(slotRightClick(QPoint)));
connect(reportDisplay, SIGNAL(itemSelectionChanged()), this, SLOT(slotMultiSelect()));
connect(reportDisplay, SIGNAL(itemChanged(QTreeWidgetItem*, int)), this, SLOT(slotDoRename(QTreeWidgetItem*, int)));
+ connect(filterEdit, SIGNAL(textChanged(const QString&)), this, SLOT(filterTree(const QString&)));
+ connect(filterShortcut, SIGNAL(activated()), filterEdit, SLOT(setFocus()));
}
void OutlinePalette::setMainWindow(ScribusMainWindow *mw)
@@ -280,6 +295,7 @@
}
}
}
+ filterTree();
}
connect(reportDisplay, SIGNAL(itemChanged(QTreeWidgetItem*, int)), this, SLOT(slotDoRename(QTreeWidgetItem*, int)));
}
@@ -603,11 +619,6 @@
selectionTriggered = false;
}
-void OutlinePalette::resizeEvent(QResizeEvent *r)
-{
- reportDisplay->resize(r->size());
-}
-
void OutlinePalette::BuildTree(bool storeVals)
{
if (!m_MainWindow || m_MainWindow->ScriptRunning)
@@ -792,11 +803,39 @@
setUpdatesEnabled(true);
if (currDoc->m_Selection->count() > 0)
slotShowSelect(0, -1);
+ filterTree();
repaint();
connect(reportDisplay, SIGNAL(itemSelectionChanged()), this, SLOT(slotMultiSelect()));
connect(reportDisplay, SIGNAL(itemChanged(QTreeWidgetItem*, int)), this, SLOT(slotDoRename(QTreeWidgetItem*, int)));
}
+void OutlinePalette::filterTree(const QString& keyword)
+{
+ OutlineTreeItem *item = NULL;
+ QTreeWidgetItemIterator it( reportDisplay );
+ while ( (*it) )
+ {
+ item = dynamic_cast<OutlineTreeItem*>(*it);
+ if (item != NULL) {
+ if ((item->type == 1) || (item->type == 3) || (item->type == 4)) {
+ if (item->PageItemObject->itemName().contains(QRegExp(keyword)))
+ item->setHidden(false);
+ else
+ item->setHidden(true);
+ } else
+ item->setHidden(false);
+ }
+
+ ++it;
+ }
+}
+
+void OutlinePalette::filterTree()
+{
+ if ( !filterEdit->text().isEmpty() )
+ filterTree( filterEdit->text() );
+}
+
void OutlinePalette::parseSubGroup(int level, OutlineTreeItem* object, QList<PageItem*> *subGroupList, int itemType)
{
QList<PageItem*> *subGroup;
@@ -858,6 +897,7 @@
{
setWindowTitle( tr("Outline"));
reportDisplay->setHeaderLabel( tr("Element"));
+ filterLabel->setText( tr("Filter:") );
}
void OutlinePalette::clearPalette()
Index: scribus/outlinepalette.h
===================================================================
--- scribus/outlinepalette.h (revision 12370)
+++ scribus/outlinepalette.h (working copy)
@@ -10,8 +10,9 @@
#include <QPixmap>
#include <QTreeWidget>
#include <QTreeWidgetItem>
-#include <QResizeEvent>
+#include <QLineEdit>
#include <QList>
+#include <QLabel>
class QEvent;
@@ -52,7 +53,6 @@
virtual void changeEvent(QEvent *e);
- void resizeEvent(QResizeEvent *r);
void setMainWindow(ScribusMainWindow *mw);
void setDoc(ScribusDoc *);
void unsetDoc();
@@ -64,6 +64,7 @@
public slots:
void BuildTree(bool storeVals = true);
+ void filterTree(const QString& keyword);
void languageChange();
void slotShowSelect(uint SNr, int Nr);
void setPaletteShown(bool);
@@ -81,8 +82,11 @@
void slotMultiSelect();
void slotSelect(QTreeWidgetItem* ite, int col);
protected:
+ void filterTree();
void clearPalette();
void createContextMenu(PageItem *currItem, double mx, double my);
+ QLabel* filterLabel;
+ QLineEdit* filterEdit;
OutlineWidget* reportDisplay;
QTreeWidgetItem* freeObjects;
QTreeWidgetItem* rootObject;