respect field column span and disable scrolling on combo fields

This commit is contained in:
itsmattkc
2019-03-13 10:22:30 +11:00
parent 36f3d0ac92
commit ec5ee40dee
6 changed files with 33 additions and 68 deletions
+4 -2
View File
@@ -1,6 +1,6 @@
#include "combofield.h" #include "combofield.h"
#include <QComboBox> #include "ui/comboboxex.h"
ComboField::ComboField(EffectRow* parent, const QString& id) : ComboField::ComboField(EffectRow* parent, const QString& id) :
EffectField(parent, id, EFFECT_FIELD_COMBO) EffectField(parent, id, EFFECT_FIELD_COMBO)
@@ -18,7 +18,9 @@ void ComboField::AddItem(const QString &text, const QVariant &data)
QWidget *ComboField::CreateWidget() QWidget *ComboField::CreateWidget()
{ {
QComboBox* cb = new QComboBox(); ComboBoxEx* cb = new ComboBoxEx();
cb->setScrollingEnabled(false);
for (int i=0;i<items_.size();i++) { for (int i=0;i<items_.size();i++) {
cb->addItem(items_.at(i).name); cb->addItem(items_.at(i).name);
+3 -1
View File
@@ -50,7 +50,8 @@ EffectField::EffectField(EffectRow* parent, const QString &i, EffectFieldType t)
QObject(parent), QObject(parent),
type_(t), type_(t),
id_(i), id_(i),
enabled_(true) enabled_(true),
colspan_(1)
{ {
// EffectField MUST be created with a parent. // EffectField MUST be created with a parent.
Q_ASSERT(parent != nullptr); Q_ASSERT(parent != nullptr);
@@ -80,6 +81,7 @@ int EffectField::GetColumnSpan()
void EffectField::SetColumnSpan(int i) void EffectField::SetColumnSpan(int i)
{ {
Q_ASSERT(i >= 1);
colspan_ = i; colspan_ = i;
} }
+5 -2
View File
@@ -1,8 +1,9 @@
#include "fontfield.h" #include "fontfield.h"
#include <QComboBox>
#include <QFontDatabase> #include <QFontDatabase>
#include "ui/comboboxex.h"
FontField::FontField(EffectRow* parent, const QString &id) : FontField::FontField(EffectRow* parent, const QString &id) :
EffectField(parent, id, EFFECT_FIELD_FONT) EffectField(parent, id, EFFECT_FIELD_FONT)
{ {
@@ -18,7 +19,9 @@ QString FontField::GetFontAt(double timecode)
QWidget *FontField::CreateWidget() QWidget *FontField::CreateWidget()
{ {
QComboBox* fcb = new QComboBox(); ComboBoxEx* fcb = new ComboBoxEx();
fcb->setScrollingEnabled(false);
fcb->addItems(font_list); fcb->addItems(font_list);
+12 -52
View File
@@ -20,63 +20,23 @@
#include "comboboxex.h" #include "comboboxex.h"
#include "project/undo.h"
#include "panels/project.h"
#include "mainwindow.h"
#include <QUndoCommand>
#include <QWheelEvent> #include <QWheelEvent>
ComboBoxEx::ComboBoxEx(QWidget *parent) :
class ComboBoxExCommand : public QUndoCommand { QComboBox(parent)
public: {
ComboBoxExCommand(ComboBoxEx* obj, int old_index, int new_index) :
combobox(obj), old_val(old_index), new_val(new_index), done(true), old_project_changed(olive::MainWindow->isWindowModified()) {}
void undo() {
combobox->setCurrentIndex(old_val);
done = false;
olive::MainWindow->setWindowModified(old_project_changed);
}
void redo() {
if (!done) {
combobox->setCurrentIndex(new_val);
}
olive::MainWindow->setWindowModified(true);
}
private:
ComboBoxEx* combobox;
int old_val;
int new_val;
bool done;
bool old_project_changed;
};
ComboBoxEx::ComboBoxEx(QWidget *parent) : QComboBox(parent), index(0) {
connect(this, SIGNAL(activated(int)), this, SLOT(index_changed(int)));
} }
void ComboBoxEx::setCurrentIndexEx(int i) { void ComboBoxEx::setScrollingEnabled(bool b)
index = i; {
setCurrentIndex(i); scrolling_enabled_ = b;
} }
void ComboBoxEx::setCurrentTextEx(const QString &text) { void ComboBoxEx::wheelEvent(QWheelEvent *e)
setCurrentText(text); {
index = currentIndex(); if (scrolling_enabled_) {
} QComboBox::wheelEvent(e);
} else {
int ComboBoxEx::getPreviousIndex() {
return previousIndex;
}
void ComboBoxEx::index_changed(int i) {
if (index != i) {
previousIndex = index;
// undo_stack.push(new ComboBoxExCommand(this, index, i));
index = i;
}
}
void ComboBoxEx::wheelEvent(QWheelEvent* e) {
e->ignore(); e->ignore();
}
} }
+5 -10
View File
@@ -22,21 +22,16 @@
#define COMBOBOXEX_H #define COMBOBOXEX_H
#include <QComboBox> #include <QComboBox>
#include <QDebug>
class ComboBoxEx : public QComboBox { class ComboBoxEx : public QComboBox {
Q_OBJECT Q_OBJECT
public: public:
ComboBoxEx(QWidget* parent = 0); ComboBoxEx(QWidget* parent = nullptr);
void setCurrentIndexEx(int i); void setScrollingEnabled(bool b);
void setCurrentTextEx(const QString &text); protected:
int getPreviousIndex(); virtual void wheelEvent(QWheelEvent* e) override;
private slots:
void index_changed(int);
private: private:
int index; bool scrolling_enabled_;
int previousIndex;
void wheelEvent(QWheelEvent* e);
}; };
#endif // COMBOBOXEX_H #endif // COMBOBOXEX_H
+4 -1
View File
@@ -36,12 +36,15 @@ EffectUI::EffectUI(Effect* e) :
layout_->addWidget(row_label, i, 0); layout_->addWidget(row_label, i, 0);
int column = 1;
for (int j=0;j<row->FieldCount();j++) { for (int j=0;j<row->FieldCount();j++) {
EffectField* field = row->Field(j); EffectField* field = row->Field(j);
QWidget* widget = field->CreateWidget(); QWidget* widget = field->CreateWidget();
layout_->addWidget(widget, i, j + 1); layout_->addWidget(widget, i, column, 1, field->GetColumnSpan());
column += field->GetColumnSpan();
} }
// Find maximum column to place keyframe controls // Find maximum column to place keyframe controls