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
+12 -52
View File
@@ -20,63 +20,23 @@
#include "comboboxex.h"
#include "project/undo.h"
#include "panels/project.h"
#include "mainwindow.h"
#include <QUndoCommand>
#include <QWheelEvent>
class ComboBoxExCommand : public QUndoCommand {
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)));
ComboBoxEx::ComboBoxEx(QWidget *parent) :
QComboBox(parent)
{
}
void ComboBoxEx::setCurrentIndexEx(int i) {
index = i;
setCurrentIndex(i);
void ComboBoxEx::setScrollingEnabled(bool b)
{
scrolling_enabled_ = b;
}
void ComboBoxEx::setCurrentTextEx(const QString &text) {
setCurrentText(text);
index = currentIndex();
}
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) {
void ComboBoxEx::wheelEvent(QWheelEvent *e)
{
if (scrolling_enabled_) {
QComboBox::wheelEvent(e);
} else {
e->ignore();
}
}
+5 -10
View File
@@ -22,21 +22,16 @@
#define COMBOBOXEX_H
#include <QComboBox>
#include <QDebug>
class ComboBoxEx : public QComboBox {
Q_OBJECT
public:
ComboBoxEx(QWidget* parent = 0);
void setCurrentIndexEx(int i);
void setCurrentTextEx(const QString &text);
int getPreviousIndex();
private slots:
void index_changed(int);
ComboBoxEx(QWidget* parent = nullptr);
void setScrollingEnabled(bool b);
protected:
virtual void wheelEvent(QWheelEvent* e) override;
private:
int index;
int previousIndex;
void wheelEvent(QWheelEvent* e);
bool scrolling_enabled_;
};
#endif // COMBOBOXEX_H
+4 -1
View File
@@ -36,12 +36,15 @@ EffectUI::EffectUI(Effect* e) :
layout_->addWidget(row_label, i, 0);
int column = 1;
for (int j=0;j<row->FieldCount();j++) {
EffectField* field = row->Field(j);
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