Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change filters dialog to use a table view. #215

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions glogg.pro
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ SOURCES += \
src/viewtools.cpp \
src/encodingspeculator.cpp \
src/gloggapp.cpp \
src/colorcombodelegate.cpp

INCLUDEPATH += src/

Expand Down Expand Up @@ -103,6 +104,7 @@ HEADERS += \
src/viewtools.h \
src/encodingspeculator.h \
src/gloggapp.h \
src/colorcombodelegate.h

isEmpty(BOOST_PATH) {
message(Building using system dynamic Boost libraries)
Expand Down
99 changes: 99 additions & 0 deletions src/colorcombodelegate.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@

#include "colorcombodelegate.h"
#include <QComboBox>

ColorComboDelegate::ColorComboDelegate(QObject* parent)
: QStyledItemDelegate(parent)
{
}

ColorComboDelegate::~ColorComboDelegate()
{
}

QWidget* ColorComboDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
// Create the combobox and populate it
QComboBox* cb = new QComboBox(parent);
const QStringList colorNames = QStringList()
// Basic 16 HTML colors (minus greys):
<< "black"
<< "white"
<< "maroon"
<< "red"
<< "purple"
<< "fuchsia"
<< "green"
<< "lime"
<< "olive"
<< "yellow"
<< "navy"
<< "blue"
<< "teal"
<< "aqua"
// Greys
<< "gainsboro"
<< "lightgrey"
<< "silver"
<< "darkgrey"
<< "grey"
<< "dimgrey"
// Reds
<< "tomato"
<< "orangered"
<< "orange"
<< "crimson"
<< "darkred"
// Greens
<< "greenyellow"
<< "lightgreen"
<< "darkgreen"
<< "lightseagreen"
// Blues
<< "lightcyan"
<< "darkturquoise"
<< "steelblue"
<< "lightblue"
<< "royalblue"
<< "darkblue"
<< "midnightblue"
// Browns
<< "bisque"
<< "tan"
<< "sandybrown"
<< "chocolate";

for ( QStringList::const_iterator i = colorNames.constBegin();
i != colorNames.constEnd(); ++i ) {
QPixmap solidPixmap( 20, 10 );
solidPixmap.fill( QColor( *i ) );
QIcon solidIcon { solidPixmap };

cb->addItem( solidIcon, *i );
}

return cb;
}

void ColorComboDelegate::setEditorData(QWidget* editor, const QModelIndex& index) const
{
if (QComboBox* cb = qobject_cast<QComboBox*>(editor)) {
// get the index of the text in the combobox that matches the current value of the itenm
QString currentText = index.data(Qt::EditRole).toString();
int cbIndex = cb->findText(currentText);
// if it is valid, adjust the combobox
if (cbIndex >= 0)
cb->setCurrentIndex(cbIndex);
} else {
QStyledItemDelegate::setEditorData(editor, index);
}
}

void ColorComboDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const
{
if (QComboBox* cb = qobject_cast<QComboBox*>(editor))
// save the current text of the combo box as the current value of the item
model->setData(index, cb->currentText(), Qt::EditRole);
else
QStyledItemDelegate::setModelData(editor, model, index);
}
18 changes: 18 additions & 0 deletions src/colorcombodelegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ifndef COLORCOMBODELEGATE_H
#define COLORCOMBODELEGATE_H

#include <QStyledItemDelegate>

class ColorComboDelegate : public QStyledItemDelegate
{
Q_OBJECT
public:

ColorComboDelegate(QObject* parent=0);
virtual ~ColorComboDelegate();
virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const;
virtual void setEditorData(QWidget* editor, const QModelIndex& index) const;
virtual void setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const;
};

#endif // COLORCOMBODELEGATE_H
Loading