Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Reformat of the filterbar

  • Loading branch information...
commit 539af18af63f63acf7e111a837644e99a5d5ed49 1 parent 0b00bc5
Pierre Marchand authored
View
159 src/filterbar.cpp
@@ -41,13 +41,17 @@
#include <QAction>
#include <QDebug>
#include <QCompleter>
+#include <QPixmap>
+#include <QPainter>
+#include <QRect>
+#include <QSettings>
QString FilterBar::andOpString = FilterBar::tr("And");
QString FilterBar::notOpString = FilterBar::tr("Not");
QString FilterBar::orOpString = FilterBar::tr("Or");
TagListModel::TagListModel(QObject *parent)
- :QAbstractTableModel(parent),
+ :QAbstractListModel(parent),
specialTagsCount(1)
{
// ui->tagsCombo->clear();
@@ -91,7 +95,38 @@ QVariant TagListModel::data(const QModelIndex &index, int role) const
QString tag(tl_tmp.at(index.row()));
if(role == Qt::DisplayRole)
+ {
+// return tag;
+ return QVariant();
+// return QString("<div style=\"color:red;\">%1</div>").arg(tag);
+ }
+ else if(role == Qt::EditRole)
return tag;
+ else if(role == Qt::DecorationRole)
+ {
+// return QVariant();
+ QRect pr(0,0,1024,18);
+ QPixmap pm(pr.size());
+ QPainter p;
+ p.begin(&pm);
+ p.drawText(pr,Qt::AlignLeft | Qt::TextDontClip | Qt::TextSingleLine, tag, &pr);
+ p.end();
+ QPixmap tagPix(pr.width() + 18, 18);
+ tagPix.fill(Qt::transparent);
+ p.begin(&tagPix);
+ p.setRenderHint(QPainter::Antialiasing);
+ p.save();
+ p.setBrush(QColor(210,210,210));
+ if(currentTags.contains(tag))
+ p.setBrush(QColor(180,180,180));
+ p.setPen(Qt::NoPen);
+ p.drawRoundedRect(tagPix.rect(), 5,5);
+ p.restore();
+ pr.translate(9,0);
+ p.drawText(pr, tag);
+ p.end();
+ return tagPix;
+ }
else if(role == TagType)
{
if(index.row() < specialTagsCount)
@@ -100,6 +135,10 @@ QVariant TagListModel::data(const QModelIndex &index, int role) const
}
return QString("TAG");
}
+ else if(role == TagString)
+ {
+ return tag;
+ }
return QVariant();
}
@@ -120,11 +159,39 @@ bool TagListModel::setData(const QModelIndex &index, const QVariant &value, int
Qt::ItemFlags TagListModel::flags(const QModelIndex &index) const
{
- if(index.row() > specialTagsCount - 1)
- return Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable;
+// if(index.row() > specialTagsCount - 1)
+// return Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable;
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
}
+void TagListModel::clearCurrents()
+{
+ if(!currentTags.isEmpty())
+ {
+ currentTags.clear();
+ emit dataChanged(index(0,0),index(FMFontDb::DB()->getTags().count() + specialTagsCount -1 ,columnCount() -1));
+ }
+}
+
+void TagListModel::addToCurrents(const QString &t)
+{
+ if(!currentTags.contains(t))
+ {
+ currentTags << t;
+ emit dataChanged(index(0,0),index(FMFontDb::DB()->getTags().count() + specialTagsCount -1 ,columnCount() -1));
+ }
+}
+
+void TagListModel::removeFromCurrents(const QString &t)
+{
+ if(currentTags.contains(t))
+ {
+ currentTags.removeAll(t);
+ emit dataChanged(index(0,0),index(FMFontDb::DB()->getTags().count() + specialTagsCount -1 ,columnCount() -1));
+ }
+}
+
+
void TagListModel::tagsDBChanged()
{
emit dataChanged(index(0,0),index(FMFontDb::DB()->getTags().count() + specialTagsCount -1 ,columnCount() -1));
@@ -137,13 +204,13 @@ FilterBar::FilterBar(QWidget *parent) :
ui->setupUi(this);
tagListModel = new TagListModel(this);
- ui->tagsView->setShowGrid(false);
- ui->tagsView->horizontalHeader()->setStretchLastSection(true);
- ui->tagsView->verticalHeader()->hide();
- ui->tagsView->horizontalHeader()->hide();
+// ui->tagsView->setShowGrid(false);
+// ui->tagsView->horizontalHeader()->setStretchLastSection(true);
+// ui->tagsView->verticalHeader()->hide();
+// ui->tagsView->horizontalHeader()->hide();
ui->tagsView->setModel(tagListModel);
- metaFieldsMenu = new QMenu(tr("Fields"), this);
+// metaFieldsMenu = new QMenu(tr("Fields"), this);
QList<FMFontDb::InfoItem> ln;
metaFieldKey = int(FMFontDb::AllInfo);
ln << FMFontDb::AllInfo
@@ -160,13 +227,14 @@ FilterBar::FilterBar(QWidget *parent) :
FMFontDb::InfoItem k(ln[gIdx]);
{
QString fieldname(FontStrings::Names().value(k));
- QAction * ma(new QAction(fieldname, metaFieldsMenu));
- ma->setData(int(k));
- metaFieldsMenu->addAction(ma);
+// QAction * ma(new QAction(fieldname, metaFieldsMenu));
+// ma->setData(int(k));
+// metaFieldsMenu->addAction(ma);
+ ui->fieldCombo->addItem(fieldname, int(k));
}
}
- ui->metadataTool->setMenu(metaFieldsMenu);
- ui->metaFieldLabel->setText(FontStrings::Names().value(FMFontDb::AllInfo));
+// ui->metadataTool->setMenu(metaFieldsMenu);
+// ui->metaFieldLabel->setText(FontStrings::Names().value(FMFontDb::AllInfo));
mModel = new QStringListModel;
mModel->setStringList(mList);
ui->metadataLineEdit->setCompleter(new QCompleter(mModel));
@@ -174,9 +242,12 @@ FilterBar::FilterBar(QWidget *parent) :
loadFilters();
connect(ui->saveButton, SIGNAL(clicked()), this, SLOT(slotSaveFilter()));
+
connect(ui->tagsView, SIGNAL(clicked(QModelIndex)), this, SLOT(slotTagSelect(QModelIndex)));
+ connect(ui->tagsView, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(slotTagEdit(QModelIndex)));
+
connect(ui->metadataLineEdit, SIGNAL(editingFinished()), this, SLOT(metaFilter()));
- connect(metaFieldsMenu, SIGNAL(triggered(QAction*)), this, SLOT(metaSelectField(QAction*)));
+ connect(ui->fieldCombo, SIGNAL(activated(int)), this, SLOT(metaSelectField(int)));
connect(ui->clearButton, SIGNAL(clicked()), this, SLOT(slotClearFilter()));
connect(ui->panoseWidget, SIGNAL(filterChanged()), this, SLOT(slotPanoFilter()));
connect(FMFontDb::DB(), SIGNAL(tagsChanged()), tagListModel, SLOT(tagsDBChanged()));
@@ -186,14 +257,20 @@ FilterBar::FilterBar(QWidget *parent) :
connect(ui->panoseArrow, SIGNAL(openChanged(bool)), this, SLOT(slotTogglePano(bool)));
connect(ui->filtersArrow, SIGNAL(openChanged(bool)), this, SLOT(slotToggleFilter(bool)));
- ui->tagsArrow->changeOpen(false);
- ui->metadataArrow->changeOpen(false);
- ui->panoseArrow->changeOpen(false);
- ui->filtersArrow->changeOpen(false);
+ QSettings settings;
+ ui->tagsArrow->changeOpen(settings.value("FilterBar/TagsOpen", true).toBool());
+ ui->metadataArrow->changeOpen(settings.value("FilterBar/MetaOpen", false).toBool());
+ ui->panoseArrow->changeOpen(settings.value("FilterBar/PanoseOpen", false).toBool());
+ ui->filtersArrow->changeOpen(settings.value("FilterBar/FiltersOpen", true).toBool());
}
FilterBar::~FilterBar()
{
+ QSettings settings;
+ settings.setValue("FilterBar/TagsOpen", ui->tagsArrow->isOpen());
+ settings.setValue("FilterBar/MetaOpen", ui->metadataArrow->isOpen());
+ settings.setValue("FilterBar/PanoseOpen", ui->panoseArrow->isOpen());
+ settings.setValue("FilterBar/FiltersOpen", ui->filtersArrow->isOpen());
delete ui;
}
@@ -385,7 +462,7 @@ void FilterBar::loadFilters()
void FilterBar::slotTagSelect(const QModelIndex & index)
{
- QString tag(tagListModel->data(index).toString());
+ QString tag(tagListModel->data(index, TagListModel::TagString).toString());
QString key(tagListModel->data(index,TagListModel::TagType).toString());
// int selCount(ui->tagsView->selectionModel()->selectedIndexes().count());
@@ -398,19 +475,43 @@ void FilterBar::slotTagSelect(const QModelIndex & index)
}
}
-
+ int andTag(ui->tagsView->getAndKey());
+ if(0 == andTag)
+ {
+ slotClearFilter();
+ tagListModel->clearCurrents();
+ }
FilterTag * ft(new FilterTag);
ft->setData(FilterData::Text, tag);
ft->setData(FilterTag::Key, key);
ft->setData(FilterTag::Tag, tag);
-// if( selCount > 1 )
-// {
-// ft->setData(FilterData::And, true);
-// ft->setData(FilterData::Or, false);
-// }
+ if(1 == andTag)
+ {
+ ft->setData(FilterData::And, true);
+ ft->setData(FilterData::Or, false);
+ }
+ else if (2 == andTag)
+ {
+ ft->setData(FilterData::And, true);
+ ft->setData(FilterData::Or, false);
+ ft->setData(FilterData::Not, true);
+ }
+ tagListModel->addToCurrents(tag);
addFilterItem(ft);
}
+void FilterBar::slotTagEdit(const QModelIndex &index)
+{
+ QString tag(tagListModel->data(index, TagListModel::TagString).toString());
+ bool ok;
+ QString newTag(QInputDialog::getText(this, tr("Fontmatrix - edit tag"), tr("Edit tag: ") + tag, QLineEdit::Normal, QString(), &ok));
+ if(!ok || newTag.isEmpty())
+ return;
+ FMFontDb::DB()->editTag(tag, newTag);
+ ui->tagsView->update(index);
+
+}
+
void FilterBar::slotPanoFilter()
{
QMap<int,QList<int> > pv(ui->panoseWidget->getFilter());
@@ -431,15 +532,17 @@ void FilterBar::slotPanoFilter()
}
-void FilterBar::metaSelectField(QAction *action)
+void FilterBar::metaSelectField(int idx)
{
- metaFieldKey = action->data().toInt();
- ui->metaFieldLabel->setText(FontStrings::Names().value(FMFontDb::InfoItem(metaFieldKey)));
+// metaFieldKey = action->data().toInt();
+// ui->metaFieldLabel->setText(FontStrings::Names().value(FMFontDb::InfoItem(metaFieldKey)));
+ metaFieldKey = ui->fieldCombo->itemData(idx).toInt();
}
void FilterBar::slotClearFilter()
{
removeAllFilters();
+ tagListModel->clearCurrents();
emit filterChanged();
}
View
48 src/filterbar.h
@@ -24,23 +24,28 @@
#include <QWidget>
#include <QList>
#include <QMap>
-#include <QAbstractTableModel>
+#include <QAbstractListModel>
+#include <QListView>
#include <QMenu>
#include <QStringListModel>
+#include <QMouseEvent>
class FiltersDialogItem;
class FilterItem;
class FilterData;
-class TagListModel : public QAbstractTableModel
+class TagListModel : public QAbstractListModel
{
Q_OBJECT
const int specialTagsCount;
+
+ QStringList currentTags;
public:
enum TagListRole
{
- TagType = Qt::UserRole
+ TagType = Qt::UserRole,
+ TagString
};
TagListModel(QObject * parent);
@@ -50,11 +55,43 @@ class TagListModel : public QAbstractTableModel
bool setData ( const QModelIndex & index, const QVariant & value, int role = Qt::EditRole );
Qt::ItemFlags flags ( const QModelIndex & index ) const;
+ void clearCurrents();
+ void addToCurrents(const QString& t);
+ void removeFromCurrents(const QString& t);
+
public slots:
void tagsDBChanged();
};
+
+class TagListView : public QListView
+{
+ Q_OBJECT
+
+ int m_andOrKey;
+public:
+ TagListView(QWidget * parent):
+ QListView(parent),
+ m_andOrKey(0)
+ {}
+
+ int getAndKey(){int ret(m_andOrKey), m_andOrKey = 0; return ret;}
+
+protected:
+ void mouseReleaseEvent(QMouseEvent *event)
+ {
+ if(event->modifiers().testFlag(Qt::ShiftModifier))
+ m_andOrKey = 1;
+ else if(event->modifiers().testFlag(Qt::ControlModifier))
+ m_andOrKey = 2;
+ else
+ m_andOrKey = 0;
+ QListView::mouseReleaseEvent(event);
+ }
+};
+
+
namespace Ui {
class FilterBar;
}
@@ -77,7 +114,7 @@ class FilterBar : public QWidget
void addFilterItem(FilterData* f, bool process = true);
void removeAllFilters();
TagListModel * tagListModel;
- QMenu * metaFieldsMenu;
+// QMenu * metaFieldsMenu;
int metaFieldKey;
QString filterString(FilterData *d, bool first = false);
@@ -98,7 +135,7 @@ private slots:
void processFilters();
void slotPanoFilter();
void metaFilter();
- void metaSelectField(QAction * action);
+ void metaSelectField(int idx);
void filtersDialog();
@@ -109,6 +146,7 @@ private slots:
void slotRemoveFilterItem(bool process = true);
void slotTagSelect(const QModelIndex & index);
+ void slotTagEdit(const QModelIndex & index);
void slotClearFilter();
void slotToggleTags(bool t);
View
254 src/filterbar.ui
@@ -30,13 +30,6 @@
<item>
<widget class="OpenCloseArrow" name="tagsArrow">
<property name="text">
- <string>-</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QLabel" name="label_2">
- <property name="text">
<string>Tags</string>
</property>
</widget>
@@ -66,40 +59,83 @@
<number>0</number>
</property>
<item row="0" column="0">
- <widget class="QTableView" name="tagsView">
+ <widget class="TagListView" name="tagsView">
+ <property name="palette">
+ <palette>
+ <active>
+ <colorrole role="Base">
+ <brush brushstyle="SolidPattern">
+ <color alpha="0">
+ <red>255</red>
+ <green>255</green>
+ <blue>255</blue>
+ </color>
+ </brush>
+ </colorrole>
+ </active>
+ <inactive>
+ <colorrole role="Base">
+ <brush brushstyle="SolidPattern">
+ <color alpha="0">
+ <red>255</red>
+ <green>255</green>
+ <blue>255</blue>
+ </color>
+ </brush>
+ </colorrole>
+ </inactive>
+ <disabled>
+ <colorrole role="Base">
+ <brush brushstyle="SolidPattern">
+ <color alpha="255">
+ <red>212</red>
+ <green>208</green>
+ <blue>200</blue>
+ </color>
+ </brush>
+ </colorrole>
+ </disabled>
+ </palette>
+ </property>
+ <property name="focusPolicy">
+ <enum>Qt::NoFocus</enum>
+ </property>
+ <property name="autoFillBackground">
+ <bool>false</bool>
+ </property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
+ <property name="horizontalScrollBarPolicy">
+ <enum>Qt::ScrollBarAlwaysOff</enum>
+ </property>
+ <property name="autoScroll">
+ <bool>false</bool>
+ </property>
<property name="editTriggers">
<set>QAbstractItemView::DoubleClicked</set>
</property>
<property name="selectionMode">
- <enum>QAbstractItemView::SingleSelection</enum>
+ <enum>QAbstractItemView::NoSelection</enum>
</property>
- <property name="showGrid">
- <bool>false</bool>
+ <property name="movement">
+ <enum>QListView::Static</enum>
</property>
- <attribute name="horizontalHeaderVisible">
- <bool>false</bool>
- </attribute>
- <attribute name="horizontalHeaderHighlightSections">
- <bool>false</bool>
- </attribute>
- <attribute name="horizontalHeaderStretchLastSection">
- <bool>true</bool>
- </attribute>
- <attribute name="verticalHeaderVisible">
- <bool>false</bool>
- </attribute>
- <attribute name="verticalHeaderDefaultSectionSize">
- <number>18</number>
- </attribute>
- <attribute name="verticalHeaderHighlightSections">
+ <property name="resizeMode">
+ <enum>QListView::Adjust</enum>
+ </property>
+ <property name="viewMode">
+ <enum>QListView::ListMode</enum>
+ </property>
+ <property name="modelColumn">
+ <number>0</number>
+ </property>
+ <property name="selectionRectVisible">
<bool>false</bool>
- </attribute>
+ </property>
</widget>
</item>
</layout>
@@ -107,7 +143,7 @@
</item>
</layout>
</item>
- <item row="1" column="0">
+ <item row="3" column="0">
<layout class="QVBoxLayout" name="verticalLayout_3">
<property name="spacing">
<number>0</number>
@@ -117,13 +153,6 @@
<item>
<widget class="OpenCloseArrow" name="metadataArrow">
<property name="text">
- <string>-</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QLabel" name="label_3">
- <property name="text">
<string>Metadata</string>
</property>
</widget>
@@ -153,43 +182,75 @@
<number>0</number>
</property>
<item row="0" column="0">
- <layout class="QHBoxLayout" name="horizontalLayout_2">
+ <layout class="QVBoxLayout" name="verticalLayout_2">
<property name="spacing">
- <number>0</number>
+ <number>3</number>
+ </property>
+ <property name="topMargin">
+ <number>3</number>
+ </property>
+ <property name="bottomMargin">
+ <number>3</number>
</property>
<item>
- <widget class="QLabel" name="metaFieldLabel">
- <property name="font">
- <font>
- <pointsize>10</pointsize>
- </font>
- </property>
- <property name="text">
- <string/>
+ <layout class="QHBoxLayout" name="horizontalLayout_6">
+ <property name="topMargin">
+ <number>0</number>
</property>
- </widget>
- </item>
- <item>
- <widget class="QLineEdit" name="metadataLineEdit"/>
+ <item>
+ <widget class="QLabel" name="label_2">
+ <property name="text">
+ <string>Search</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLineEdit" name="metadataLineEdit">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>172</width>
+ <height>0</height>
+ </size>
+ </property>
+ </widget>
+ </item>
+ </layout>
</item>
<item>
- <widget class="QToolButton" name="metadataTool">
- <property name="toolTip">
- <string>Select field</string>
- </property>
- <property name="text">
- <string>...</string>
- </property>
- <property name="popupMode">
- <enum>QToolButton::InstantPopup</enum>
- </property>
- <property name="autoRaise">
- <bool>false</bool>
- </property>
- <property name="arrowType">
- <enum>Qt::DownArrow</enum>
+ <layout class="QHBoxLayout" name="horizontalLayout_2">
+ <property name="topMargin">
+ <number>0</number>
</property>
- </widget>
+ <item>
+ <widget class="QLabel" name="label">
+ <property name="text">
+ <string>in</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QComboBox" name="fieldCombo">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>172</width>
+ <height>0</height>
+ </size>
+ </property>
+ </widget>
+ </item>
+ </layout>
</item>
</layout>
</item>
@@ -198,23 +259,22 @@
</item>
</layout>
</item>
- <item row="2" column="0">
+ <item row="5" column="0">
<layout class="QVBoxLayout" name="verticalLayout_4">
<property name="spacing">
<number>0</number>
</property>
+ <property name="topMargin">
+ <number>3</number>
+ </property>
+ <property name="bottomMargin">
+ <number>3</number>
+ </property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="OpenCloseArrow" name="panoseArrow">
<property name="text">
- <string>-</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QLabel" name="label_4">
- <property name="text">
<string>Panose</string>
</property>
</widget>
@@ -251,23 +311,19 @@
</item>
</layout>
</item>
- <item row="3" column="0">
+ <item row="7" column="0">
<layout class="QVBoxLayout" name="verticalLayout_5">
<property name="spacing">
<number>0</number>
</property>
+ <property name="topMargin">
+ <number>3</number>
+ </property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="OpenCloseArrow" name="filtersArrow">
<property name="text">
- <string>-</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QLabel" name="label_5">
- <property name="text">
<string>Filters</string>
</property>
</widget>
@@ -310,7 +366,7 @@
<x>0</x>
<y>0</y>
<width>223</width>
- <height>152</height>
+ <height>128</height>
</rect>
</property>
<property name="sizePolicy">
@@ -339,7 +395,7 @@
</item>
</layout>
</item>
- <item row="6" column="0">
+ <item row="10" column="0">
<layout class="QVBoxLayout" name="verticalLayout_6">
<property name="spacing">
<number>0</number>
@@ -429,7 +485,7 @@
</item>
</layout>
</item>
- <item row="4" column="0">
+ <item row="8" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
@@ -442,13 +498,34 @@
</property>
</spacer>
</item>
- <item row="5" column="0">
+ <item row="9" column="0">
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
+ <item row="4" column="0">
+ <widget class="Line" name="line_3">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="0">
+ <widget class="Line" name="line_2">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ </widget>
+ </item>
+ <item row="6" column="0">
+ <widget class="Line" name="line_4">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ </widget>
+ </item>
</layout>
</widget>
<customwidgets>
@@ -463,6 +540,11 @@
<extends>QLabel</extends>
<header>openclosearrow.h</header>
</customwidget>
+ <customwidget>
+ <class>TagListView</class>
+ <extends>QListView</extends>
+ <header>filterbar.h</header>
+ </customwidget>
</customwidgets>
<resources/>
<connections/>
View
1  src/fmpreviewlist.cpp
@@ -356,6 +356,7 @@ FMPreviewView::FMPreviewView(QWidget * parent):
setDragEnabled(true);
setDragDropMode(QAbstractItemView::DragDrop);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ setSelectionRectVisible(false);
}
bool FMPreviewView::moveTo(const QString &fname)
View
1  src/mainviewwidget.cpp
@@ -124,6 +124,7 @@ MainViewWidget::MainViewWidget ( QWidget *parent )
MainViewWidget::~MainViewWidget()
{
+ delete filterBar;
}
View
17 src/openclosearrow.cpp
@@ -4,7 +4,7 @@ OpenCloseArrow::OpenCloseArrow(QWidget *parent, bool open) :
QLabel(parent),
openingState(open)
{
- setOpText();
+// setOpText();
}
OpenCloseArrow::~OpenCloseArrow()
@@ -31,8 +31,19 @@ void OpenCloseArrow::changeOpen(bool t)
void OpenCloseArrow::setOpText()
{
+ if(baseText.isEmpty())
+ baseText = text();
+ QFont f(font());
if(openingState)
- setText("-");
+ {
+ f.setBold(true);
+ setFont(f);
+ setText(QString("%1").arg(baseText));
+ }
else
- setText("+");
+ {
+ f.setBold(false);
+ setFont(f);
+ setText(QString("%1").arg(baseText));
+ }
}
View
20 src/openclosearrow.h
@@ -6,26 +6,28 @@
class OpenCloseArrow : public QLabel
{
- Q_OBJECT
+ Q_OBJECT
+
+ QString baseText;
public:
- explicit OpenCloseArrow(QWidget *parent = 0, bool open = true);
- ~OpenCloseArrow();
+ explicit OpenCloseArrow(QWidget *parent = 0, bool open = true);
+ ~OpenCloseArrow();
- bool isOpen() const {return openingState;}
+ bool isOpen() const {return openingState;}
private:
- bool openingState;
- void setOpText();
+ bool openingState;
+ void setOpText();
protected:
- void mouseReleaseEvent( QMouseEvent * ev );
+ void mouseReleaseEvent( QMouseEvent * ev );
signals:
- void openChanged(bool);
+ void openChanged(bool);
public slots:
- void changeOpen(bool t);
+ void changeOpen(bool t);
};
View
128 src/panosewidget.cpp
@@ -22,8 +22,13 @@
#include "ui_panosewidget.h"
#include "panosemodel.h"
#include "fmfontstrings.h"
+#include "fmpaths.h"
#include <QTreeWidgetItem>
+#include <QDir>
+#include <QSettings>
+#include <QIcon>
+#include <QColor>
PanoseWidget::PanoseWidget(QWidget *parent) :
@@ -31,16 +36,43 @@ PanoseWidget::PanoseWidget(QWidget *parent) :
m_ui(new Ui::PanoseWidget)
{
m_ui->setupUi(this);
- attributeModel = new PanoseAttributeModel( this);
- valueModel = new PanoseValueModel( this);
- m_ui->attributeView->setModel(attributeModel);
- m_ui->valueView->setModel(valueModel);
- m_ui->pTree->hide();
m_filter.clear();
m_filterKey = 0;
- doConnect(true);
+
+ const QMap< FontStrings::PanoseKey, QMap<int, QString> >& p(FontStrings::Panose());
+ QSettings settings;
+ QString defaultDir(FMPaths::ResourcesDir() + "Panose/Icons");
+ QString pDir(settings.value("Panose/IconDir", defaultDir).toString() + QDir::separator());
+
+ foreach(const FontStrings::PanoseKey& k, p.keys())
+ {
+ QString fn(pDir + QString::number(k) + QDir::separator() + "attribute.png");
+ QTreeWidgetItem * pItem(new QTreeWidgetItem(m_ui->pTree));
+
+ pItem->setText(0, FontStrings::PanoseKeyName(k));
+ pItem->setData(0,Qt::UserRole,k);
+ if(QFile::exists(fn))
+ pItem->setIcon(0, QIcon(fn));
+
+ foreach(const int& v, p[k].keys())
+ {
+ if(v > 1) // We do not want "Any" and "No Fit"
+ {
+ QString fn2(pDir + QString::number(k) + QDir::separator() + QString::number(v) +".png");
+
+ QTreeWidgetItem * item(new QTreeWidgetItem(pItem));
+ item->setText(0, p[k][v]);
+ item->setData(0,Qt::UserRole,v);
+ item->setForeground(0, QColor(qrand() % 255, qrand() % 255, qrand() % 255));
+ if(QFile::exists(fn2))
+ item->setIcon(0, QIcon(fn2));
+ }
+ }
+ }
+
+ connect(m_ui->pTree, SIGNAL(itemClicked(QTreeWidgetItem * , int )), this, SLOT(slotSelect(QTreeWidgetItem * , int )));
}
PanoseWidget::~PanoseWidget()
@@ -53,91 +85,27 @@ void PanoseWidget::doConnect(const bool &c)
{
if(c)
{
- connect(m_ui->attributeView, SIGNAL(activated (const QModelIndex&)), this, SLOT(slotChangeAtrr(const QModelIndex&)));
- connect(m_ui->valueView->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(slotUpdateFilter(const QItemSelection & , const QItemSelection &)));
- connect(m_ui->pTree, SIGNAL(activated(QModelIndex)), this, SLOT(slotSelectAttr(QModelIndex)));
+ connect(m_ui->pTree, SIGNAL(clicked(QTreeWidgetItem * , int )), this, SLOT(slotSelect(QTreeWidgetItem * , int )));
}
else
{
- disconnect(m_ui->attributeView, SIGNAL(activated (const QModelIndex&)), this, SLOT(slotChangeAtrr(const QModelIndex&)));
- disconnect(m_ui->valueView->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(slotUpdateFilter(const QItemSelection & , const QItemSelection &)));
- disconnect(m_ui->pTree, SIGNAL(activated(QModelIndex)), this, SLOT(slotSelectAttr(QModelIndex)));
+ disconnect(m_ui->pTree, SIGNAL(clicked(QTreeWidgetItem * , int )), this, SLOT(slotSelect(QTreeWidgetItem * , int )));
}
}
-void PanoseWidget::slotChangeAtrr(const QModelIndex& index)
+void PanoseWidget::slotSelect(QTreeWidgetItem *item, int column)
{
- if(index.isValid())
- {
- m_filterKey = index.row();
- valueModel->setCat(m_filterKey);
- disconnect(m_ui->valueView->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(slotUpdateFilter(const QItemSelection & , const QItemSelection &)));
- m_ui->valueView->clearSelection();
- if(m_filter.contains(m_filterKey) && !m_filter[m_filterKey].isEmpty())
- {
- foreach(const int& r, m_filter[m_filterKey])
- {
- m_ui->valueView->selectionModel()->select(valueModel->index(r), QItemSelectionModel::Select);
- }
- }
- connect(m_ui->valueView->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(slotUpdateFilter(const QItemSelection & , const QItemSelection &)));
- }
-}
+ if(column > 0 )
+ return;
+ if(item->childCount() > 0)
+ return;
+ int pValue(item->parent()->data(0,Qt::UserRole).toInt());
+ int cValue(item->data(0,Qt::UserRole).toInt());
-void PanoseWidget::slotUpdateFilter(const QItemSelection & selected, const QItemSelection & deselected)
-{
m_filter.clear();
- QList<int> ns;
- foreach(const QModelIndex& i, m_ui->valueView->selectionModel()->selectedIndexes())
- {
- ns << i.row() + 2; // since "0" and "1" has been removed from the list
- }
- if(ns.count())
- m_filter[m_filterKey] = ns;
- else
- m_filter.remove(m_filterKey);
-
- m_ui->pTree->clear();
- foreach(const int& k, m_filter.keys())
- {
- QTreeWidgetItem *pItem(new QTreeWidgetItem(m_ui->pTree));
- pItem->setText(0, FontStrings::PanoseKeyName(FontStrings::PanoseKey(k)));
- foreach(const int& v, m_filter[k])
- {
- QTreeWidgetItem *item(new QTreeWidgetItem(pItem));
- item->setText(0, FontStrings::Panose().value( FontStrings::PanoseKey(k) )[v]);
- }
- pItem->setExpanded(true);
- }
-
-
+ m_filter.insert(pValue,QList<int>() << cValue);
emit filterChanged();
- doConnect(false);
- m_ui->attributeView->clearSelection();
- m_ui->valueView->clearSelection();
- doConnect(true);
-// hide();
-}
-
-void PanoseWidget::slotSelectAttr(const QModelIndex& idx)
-{
- QModelIndex tmpIdx(idx);
- while(tmpIdx.parent().isValid())
- tmpIdx = tmpIdx.parent();
-
- const QString cs(tmpIdx.data(Qt::DisplayRole).toString());
- for(int i(0); i < m_ui->attributeView->model()->rowCount(); ++i)
- {
- const QModelIndex &cIdx(m_ui->attributeView->model()->index(i,0));
- if(cs == cIdx.data(Qt::DisplayRole).toString())
- {
- m_ui->attributeView->setCurrentIndex(cIdx);
- slotChangeAtrr(cIdx);
- return;
- }
- }
-
}
void PanoseWidget::setFilter(const QMap<int, QList<int> >& filter)
View
10 src/panosewidget.h
@@ -22,11 +22,9 @@
#define PANOSEWIDGET_H
#include <QtGui/QWidget>
-#include <QModelIndex>
#include <QItemSelection>
-class PanoseValueModel;
-class PanoseAttributeModel;
+class QTreeWidgetItem;
namespace Ui {
class PanoseWidget;
@@ -49,8 +47,6 @@ class PanoseWidget : public QWidget {
private:
Ui::PanoseWidget *m_ui;
- PanoseAttributeModel * attributeModel;
- PanoseValueModel * valueModel;
int m_filterKey;
QMap<int, QList<int> > m_filter;
@@ -58,9 +54,7 @@ class PanoseWidget : public QWidget {
void doConnect(const bool& c);
private slots:
- void slotChangeAtrr(const QModelIndex& idx);
- void slotUpdateFilter(const QItemSelection & selected, const QItemSelection & deselected);
- void slotSelectAttr(const QModelIndex& idx);
+ void slotSelect(QTreeWidgetItem * item, int column);
signals:
void filterChanged();
View
137 src/panosewidget.ui
@@ -15,123 +15,9 @@
</property>
<layout class="QGridLayout" name="gridLayout_2">
<property name="margin">
- <number>2</number>
+ <number>0</number>
</property>
<item row="0" column="0">
- <widget class="QWidget" name="widget" native="true">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
- <horstretch>0</horstretch>
- <verstretch>2</verstretch>
- </sizepolicy>
- </property>
- <layout class="QGridLayout" name="gridLayout">
- <property name="margin">
- <number>0</number>
- </property>
- <property name="spacing">
- <number>0</number>
- </property>
- <item row="0" column="0">
- <widget class="QListView" name="attributeView">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
- <horstretch>1</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="frameShape">
- <enum>QFrame::NoFrame</enum>
- </property>
- <property name="horizontalScrollBarPolicy">
- <enum>Qt::ScrollBarAlwaysOff</enum>
- </property>
- <property name="textElideMode">
- <enum>Qt::ElideNone</enum>
- </property>
- <property name="movement">
- <enum>QListView::Static</enum>
- </property>
- <property name="flow">
- <enum>QListView::TopToBottom</enum>
- </property>
- <property name="resizeMode">
- <enum>QListView::Adjust</enum>
- </property>
- <property name="viewMode">
- <enum>QListView::ListMode</enum>
- </property>
- <property name="modelColumn">
- <number>0</number>
- </property>
- <property name="uniformItemSizes">
- <bool>false</bool>
- </property>
- <property name="wordWrap">
- <bool>true</bool>
- </property>
- </widget>
- </item>
- <item row="0" column="2">
- <widget class="QListView" name="valueView">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
- <horstretch>2</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="frameShape">
- <enum>QFrame::NoFrame</enum>
- </property>
- <property name="horizontalScrollBarPolicy">
- <enum>Qt::ScrollBarAlwaysOff</enum>
- </property>
- <property name="dragDropMode">
- <enum>QAbstractItemView::NoDragDrop</enum>
- </property>
- <property name="selectionMode">
- <enum>QAbstractItemView::ExtendedSelection</enum>
- </property>
- <property name="iconSize">
- <size>
- <width>64</width>
- <height>64</height>
- </size>
- </property>
- <property name="textElideMode">
- <enum>Qt::ElideNone</enum>
- </property>
- <property name="movement">
- <enum>QListView::Static</enum>
- </property>
- <property name="flow">
- <enum>QListView::TopToBottom</enum>
- </property>
- <property name="resizeMode">
- <enum>QListView::Adjust</enum>
- </property>
- <property name="viewMode">
- <enum>QListView::IconMode</enum>
- </property>
- <property name="modelColumn">
- <number>0</number>
- </property>
- <property name="uniformItemSizes">
- <bool>true</bool>
- </property>
- </widget>
- </item>
- <item row="0" column="1">
- <widget class="Line" name="line">
- <property name="orientation">
- <enum>Qt::Vertical</enum>
- </property>
- </widget>
- </item>
- </layout>
- </widget>
- </item>
- <item row="1" column="0">
<widget class="QTreeWidget" name="pTree">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
@@ -139,6 +25,27 @@
<verstretch>1</verstretch>
</sizepolicy>
</property>
+ <property name="focusPolicy">
+ <enum>Qt::NoFocus</enum>
+ </property>
+ <property name="editTriggers">
+ <set>QAbstractItemView::NoEditTriggers</set>
+ </property>
+ <property name="selectionMode">
+ <enum>QAbstractItemView::SingleSelection</enum>
+ </property>
+ <property name="indentation">
+ <number>12</number>
+ </property>
+ <property name="rootIsDecorated">
+ <bool>true</bool>
+ </property>
+ <property name="animated">
+ <bool>true</bool>
+ </property>
+ <attribute name="headerVisible">
+ <bool>false</bool>
+ </attribute>
<column>
<property name="text">
<string>Panose Attributes</string>
View
5 src/typotek.cpp
@@ -311,10 +311,12 @@ void typotek::closeEvent ( QCloseEvent *event )
{
f->close();
}
+ writeSettings();
+
delete PlayWidget::getInstance();
delete FontCompareWidget::getInstance();
+ delete theMainView;
- writeSettings();
event->accept();
}
@@ -1021,7 +1023,6 @@ bool typotek::maybeSave()
typotek::~typotek()
{
-
}
void typotek::fillTagsList()
Please sign in to comment.
Something went wrong with that request. Please try again.