git-svn-id: svn://db.shs.com.ru/libs@457 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
@@ -7,6 +7,7 @@ HistoryView::HistoryView(QWidget* parent): QListWidget(parent) {
|
||||
setSelectionMode(QAbstractItemView::MultiSelection);
|
||||
setEditTriggers(NoEditTriggers);
|
||||
active_ = true;
|
||||
duplicates_ = false;
|
||||
index = 0;
|
||||
setLimit(32);
|
||||
setHistoryColor(palette().color(QPalette::Highlight));
|
||||
@@ -20,19 +21,34 @@ HistoryView::~HistoryView() {
|
||||
}
|
||||
|
||||
|
||||
QByteArray HistoryView::current() const {
|
||||
QListWidgetItem * ci = currentItem();
|
||||
if (!ci) return QByteArray();
|
||||
int i = row(ci);
|
||||
if (i < 0 || i >= history_.size()) return QByteArray();
|
||||
return history_[i].command;
|
||||
}
|
||||
|
||||
|
||||
void HistoryView::addEntry(int action, int count_, const QString & suffix) {
|
||||
if (!active_) return;
|
||||
QByteArray ba;
|
||||
emit commandRequest(ba);
|
||||
if (!duplicates_)
|
||||
if (current() == ba)
|
||||
return;
|
||||
int cnt = count();
|
||||
for (int i = index; i < cnt; ++i)
|
||||
if (i >= 0) delete takeItem(index);
|
||||
addItem(new QListWidgetItem(actions_.value(action).icon, actionText(action, count_) + suffix));
|
||||
QListWidgetItem * li = new QListWidgetItem(actions_.value(action).icon, actionText(action, count_) + suffix);
|
||||
blockSignals(true);
|
||||
addItem(li);
|
||||
setCurrentItem(li);
|
||||
index = count();
|
||||
history_.resize(index);
|
||||
history_.back() = Entry(action);
|
||||
history_.back() = Entry(action, ba);
|
||||
checkLimit();
|
||||
emit commandRequest(history_.back().command);
|
||||
scrollToItem(item(index - 1));
|
||||
blockSignals(true);
|
||||
for (int i = 0; i < index; ++i)
|
||||
item(i)->setSelected(true);
|
||||
blockSignals(false);
|
||||
@@ -87,6 +103,7 @@ void HistoryView::itemSelectionChanged() {
|
||||
if (index < 1) index = 1;
|
||||
//qDebug() << "changed" << count();
|
||||
blockSignals(true);
|
||||
setCurrentItem(item(index - 1));
|
||||
for (int i = 0; i < index; ++i)
|
||||
item(i)->setSelected(true);
|
||||
for (int i = index; i < count(); ++i)
|
||||
|
||||
@@ -9,6 +9,7 @@ class HistoryView: public QListWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(bool active READ isActive WRITE setActive)
|
||||
Q_PROPERTY(bool duplicatesEnabled READ isDuplicatesEnabled WRITE setDuplicatesEnabled)
|
||||
Q_PROPERTY(int limit READ limit WRITE setLimit)
|
||||
Q_PROPERTY(QColor historyColor READ historyColor WRITE setHistoryColor)
|
||||
public:
|
||||
@@ -16,8 +17,10 @@ public:
|
||||
~HistoryView();
|
||||
|
||||
bool isActive() const {return active_;}
|
||||
bool isDuplicatesEnabled() const {return duplicates_;}
|
||||
int limit() const {return limit_;}
|
||||
QColor historyColor() const {return color_;}
|
||||
QByteArray current() const;
|
||||
|
||||
void addEntry(int action, int count = 0, const QString & suffix = QString());
|
||||
void registerAction(int action, const QString & text, const QImage & icon = QImage());
|
||||
@@ -47,11 +50,12 @@ private:
|
||||
QMap<int, Action> actions_;
|
||||
QVector<Entry> history_;
|
||||
QColor color_;
|
||||
bool active_;
|
||||
bool active_, duplicates_;
|
||||
int index, limit_;
|
||||
|
||||
public slots:
|
||||
void setActive(bool yes) {active_ = yes;}
|
||||
void setDuplicatesEnabled(bool yes) {duplicates_ = yes;}
|
||||
void setLimit(int l);
|
||||
void setHistoryColor(const QColor & c);
|
||||
void clear(bool silent = false);
|
||||
|
||||
@@ -126,6 +126,10 @@ QString uniqueName(QString n, const QStringList & names) {
|
||||
|
||||
|
||||
int fontHeight() {
|
||||
#ifdef Q_OS_ANDROID
|
||||
static int ret = QApplication::fontMetrics().size(0, "0").height();
|
||||
return ret;
|
||||
#endif
|
||||
return QApplication::fontMetrics().size(0, "0").height();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user