ledok
This commit is contained in:
parent
a69c444f2c
commit
0cb71807e6
|
@ -1,4 +1,5 @@
|
|||
#include "qgui.h"
|
||||
#include <QResizeEvent>
|
||||
|
||||
const int AlignRight = Qt::AlignRight | Qt::AlignVCenter;
|
||||
|
||||
|
@ -8,26 +9,31 @@ Table::Table(std::initializer_list<ColAttr> colAttrs, int rows, QWidget *parent)
|
|||
auto item = horizontalHeaderItem(i);
|
||||
if(item==0) setHorizontalHeaderItem(i, item = new QTableWidgetItem());
|
||||
item->setText(it->text);
|
||||
item->setData(0x99, it->width);
|
||||
if(it->width > 0) horizontalHeader()->resizeSection(i, it->width);
|
||||
if(it->resizeMode > -1) horizontalHeader()->setSectionResizeMode(i, (QHeaderView::ResizeMode)it->resizeMode);
|
||||
if(it->resizeMode != QHeaderView::Interactive) {
|
||||
if(it->resizeMode==QHeaderView::Stretch && it->width>0) {
|
||||
item->setData(0x99, it->width > 0 ? it->width : 100);
|
||||
noStretch = false;
|
||||
} else horizontalHeader()->setSectionResizeMode(i, (QHeaderView::ResizeMode)it->resizeMode);
|
||||
}
|
||||
mFieldMap.insert(it->field, i++);
|
||||
}
|
||||
}
|
||||
|
||||
int Table::sizeHintForColumn(int column) const {
|
||||
auto item = horizontalHeaderItem(column);
|
||||
if(item==0) return QTableWidget::sizeHintForColumn(column);
|
||||
int width = item->data(0x99).toInt();
|
||||
if(width==0) return QTableWidget::sizeHintForColumn(column);
|
||||
void Table::resizeEvent(QResizeEvent *event) {
|
||||
QTableWidget::resizeEvent(event);
|
||||
if(noStretch || event->size().width() == event->oldSize().width()) return;
|
||||
resizeSec();
|
||||
}
|
||||
|
||||
void Table::resizeSec() {
|
||||
auto header = horizontalHeader();
|
||||
if(header->sectionResizeMode(column) != QHeaderView::ResizeToContents) return QTableWidget::sizeHintForColumn(column);
|
||||
int colCnt = columnCount();
|
||||
int remainWidth = header->width(), stretchWidth = width;
|
||||
for(int cc=0; cc<colCnt; cc++) if(cc!=column && (item = horizontalHeaderItem(cc))) {
|
||||
if(header->sectionResizeMode(cc) == QHeaderView::ResizeToContents) stretchWidth += item->data(0x99).toInt();
|
||||
else remainWidth -= item->data(0x99).toInt();
|
||||
int colCnt = columnCount(), remainWidth = header->width(), stretchWidth = 0, secWidth;
|
||||
QTableWidgetItem *item;
|
||||
for(int cc=0; cc<colCnt; cc++) if((item = horizontalHeaderItem(cc))) {
|
||||
if((secWidth = item->data(0x99).toInt()) > 0) stretchWidth += secWidth;
|
||||
else remainWidth -= header->sectionSize(cc);
|
||||
}
|
||||
if(remainWidth<=0) return QTableWidget::sizeHintForColumn(column);
|
||||
return width * remainWidth / stretchWidth;
|
||||
if(remainWidth<=0 || stretchWidth==0) return;
|
||||
for(int cc=0; cc<colCnt; cc++) if((item = horizontalHeaderItem(cc)) && (secWidth = item->data(0x99).toInt()) > 0) header->resizeSection(cc, secWidth * remainWidth / stretchWidth);
|
||||
}
|
||||
|
|
|
@ -3,9 +3,12 @@
|
|||
|
||||
#include <QComboBox>
|
||||
#include <QStackedLayout>
|
||||
#include <QSplitter>
|
||||
#include <QListWidget>
|
||||
#include <QTableWidget>
|
||||
#include <QHeaderView>
|
||||
#include <QLabel>
|
||||
#include <QTextEdit>
|
||||
|
||||
#define MainMust \
|
||||
#if(QT_VERSION_MAJOR > 5) \
|
||||
|
@ -24,6 +27,34 @@ inline int setCurrentData(QComboBox *combo, const QVariant &data) {
|
|||
if(idx>-1) combo->setCurrentIndex(idx);
|
||||
return idx;
|
||||
}
|
||||
inline void gFont(QWidget *wgt, int size, bool bold = false, bool italic = false) {
|
||||
auto ft = wgt->font();
|
||||
ft.setPixelSize(size);
|
||||
if(bold) ft.setBold(true);
|
||||
if(italic) ft.setItalic(true);
|
||||
wgt->setFont(ft);
|
||||
}
|
||||
inline void gFont(QWidget *wgt, const QString &family, int size = 0, bool bold = false, bool italic = false) {
|
||||
auto ft = wgt->font();
|
||||
ft.setFamily(family);
|
||||
if(size) ft.setPixelSize(size);
|
||||
if(bold) ft.setBold(true);
|
||||
if(italic) ft.setItalic(true);
|
||||
wgt->setFont(ft);
|
||||
}
|
||||
inline QFont qfont(const QString &family, int pixelSize, bool bold = false, bool italic = false) {
|
||||
QFont ft(family);
|
||||
ft.setPixelSize(pixelSize);
|
||||
if(bold) ft.setBold(true);
|
||||
if(italic) ft.setItalic(true);
|
||||
return ft;
|
||||
}
|
||||
inline void gAppendText(QTextEdit *wgt, const QString &text, const QColor &color) {
|
||||
auto c0 = wgt->textColor();
|
||||
wgt->setTextColor(color);
|
||||
wgt->append(text);
|
||||
wgt->setTextColor(c0);
|
||||
}
|
||||
|
||||
class VBox : public QBoxLayout {
|
||||
public:
|
||||
|
@ -37,6 +68,17 @@ public:
|
|||
wgt->setLayout(this);
|
||||
parent->addWidget(wgt);
|
||||
};
|
||||
inline VBox(QSplitter *parent) : QBoxLayout(TopToBottom) {
|
||||
setContentsMargins(0,0,0,0);
|
||||
auto wgt = new QWidget;
|
||||
wgt->setLayout(this);
|
||||
parent->addWidget(wgt);
|
||||
};
|
||||
inline QLabel *addLabel(const QString &text) {
|
||||
auto lb = new QLabel(text);
|
||||
addWidget(lb);
|
||||
return lb;
|
||||
}
|
||||
};
|
||||
class HBox : public QBoxLayout {
|
||||
public:
|
||||
|
@ -50,6 +92,17 @@ public:
|
|||
wgt->setLayout(this);
|
||||
parent->addWidget(wgt);
|
||||
};
|
||||
inline HBox(QSplitter *parent) : QBoxLayout(LeftToRight) {
|
||||
setContentsMargins(0,0,0,0);
|
||||
auto wgt = new QWidget;
|
||||
wgt->setLayout(this);
|
||||
parent->addWidget(wgt);
|
||||
};
|
||||
inline QLabel *addLabel(const QString &text) {
|
||||
auto lb = new QLabel(text);
|
||||
addWidget(lb);
|
||||
return lb;
|
||||
}
|
||||
};
|
||||
class Grid : public QGridLayout {
|
||||
public:
|
||||
|
@ -64,14 +117,6 @@ public:
|
|||
};
|
||||
};
|
||||
|
||||
inline QFont qfont(const QString &family, int pixelSize, bool bold = false, bool italic = false) {
|
||||
QFont font(family);
|
||||
font.setPixelSize(pixelSize);
|
||||
if(bold) font.setBold(true);
|
||||
if(italic) font.setItalic(true);
|
||||
return font;
|
||||
}
|
||||
|
||||
class ListWgt : public QListWidget {
|
||||
public:
|
||||
using QListWidget::QListWidget;
|
||||
|
@ -86,15 +131,18 @@ public:
|
|||
};
|
||||
|
||||
struct ColAttr {
|
||||
ColAttr(QString field, QString text, int width=0, QHeaderView::ResizeMode resizeMode = QHeaderView::Interactive) : field(field), text(text), width(width), resizeMode(resizeMode) {}
|
||||
ColAttr(QString field, QString text, QHeaderView::ResizeMode resizeMode) : field(field), text(text), resizeMode(resizeMode) {}
|
||||
QString field;
|
||||
QString text;
|
||||
int width{0};
|
||||
int resizeMode{-1};
|
||||
QHeaderView::ResizeMode resizeMode;
|
||||
};
|
||||
class Table : public QTableWidget {
|
||||
Q_OBJECT
|
||||
public:
|
||||
using QTableWidget::QTableWidget;
|
||||
Table() {}
|
||||
Table(std::initializer_list<ColAttr> colAttrs, int rows = 0, QWidget *parent = 0);
|
||||
|
||||
inline auto setNoEdit() {
|
||||
|
@ -123,12 +171,16 @@ public:
|
|||
verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
||||
return this;
|
||||
}
|
||||
inline auto setColWidth(int value) {
|
||||
horizontalHeader()->setDefaultSectionSize(value);
|
||||
inline auto setColWidth(int value, QHeaderView::ResizeMode mode = QHeaderView::Interactive) {
|
||||
auto header = horizontalHeader();
|
||||
header->setDefaultSectionSize(value);
|
||||
if(mode!=QHeaderView::Interactive) header->setSectionResizeMode(mode);
|
||||
return this;
|
||||
}
|
||||
inline auto setRowHeight(int value) {
|
||||
verticalHeader()->setDefaultSectionSize(value);
|
||||
inline auto setRowHeight(int value, QHeaderView::ResizeMode mode = QHeaderView::Interactive) {
|
||||
auto header = verticalHeader();
|
||||
header->setDefaultSectionSize(value);
|
||||
if(mode!=QHeaderView::Interactive) header->setSectionResizeMode(mode);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -143,6 +195,13 @@ public:
|
|||
return setHeaderText(col, text);
|
||||
}
|
||||
|
||||
inline auto setVHeaderText(int row, QString text) {
|
||||
auto item = verticalHeaderItem(row);
|
||||
if(item==0) setVerticalHeaderItem(row, item = new QTableWidgetItem());
|
||||
item->setText(text);
|
||||
return item;
|
||||
}
|
||||
|
||||
inline auto appendRow() {
|
||||
auto value = rowCount();
|
||||
setRowCount(value + 1);
|
||||
|
@ -226,9 +285,10 @@ public Q_SLOTS:
|
|||
inline void clearRows() {setRowCount(0);}
|
||||
|
||||
protected:
|
||||
int sizeHintForColumn(int column) const override;
|
||||
|
||||
void resizeEvent(QResizeEvent *event) override;
|
||||
void resizeSec();
|
||||
QMap<QString,int> mFieldMap;
|
||||
bool noStretch{true};
|
||||
};
|
||||
|
||||
class ResizeEmitedWgt : public QWidget {
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
#include "program/eweb.h"
|
||||
#include "program/wplanlist.h"
|
||||
#include "tools.h"
|
||||
#include <QBoxLayout>
|
||||
#include <QDateEdit>
|
||||
#include <QDir>
|
||||
#include <QGraphicsView>
|
||||
|
@ -35,7 +34,10 @@ public:
|
|||
};
|
||||
|
||||
PageListItem::PageListItem(const QJsonObject &attr, const QString &pageDir) : mAttr(attr), mPageDir(pageDir) {
|
||||
setSizeHint(QSize(0,80));
|
||||
scale = qMin(128.0 / gProgItem->mWidth, 96.0 / gProgItem->mHeight);
|
||||
viewW = scale * gProgItem->mWidth;
|
||||
viewH = scale * gProgItem->mHeight;
|
||||
setSizeHint(QSize(0, viewH+20));
|
||||
mScene = new PageScene(0, 0, gProgItem->mWidth, gProgItem->mHeight, this);
|
||||
auto elements = mAttr["elements"].toArray();
|
||||
foreach(auto ele, elements) {
|
||||
|
@ -124,31 +126,39 @@ bool PageListItem::saveFiles() {
|
|||
|
||||
QWidget *PageListItem::itemWgt() {
|
||||
auto wgtPage = new QWidget;
|
||||
auto hBox = new HBox(wgtPage);
|
||||
auto grid = new Grid(wgtPage);
|
||||
grid->setContentsMargins(0,0,0,0);
|
||||
grid->setSpacing(0);
|
||||
|
||||
mGraView = new QGraphicsView();
|
||||
grid->addWidget(fdIdx = new QLabel, 0, 0);
|
||||
fdIdx->setMinimumWidth(32);
|
||||
fdIdx->setAlignment(Qt::AlignCenter);
|
||||
fdIdx->setNum(listWidget()->count());
|
||||
|
||||
mGraView = new QGraphicsView;
|
||||
mGraView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
mGraView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
mGraView->setEnabled(false);
|
||||
mGraView->setFrameShape(QFrame::NoFrame);
|
||||
mGraView->setFixedSize(120, 60);
|
||||
mGraView->setFixedSize(viewW, viewH);
|
||||
mGraView->setStyleSheet("QGraphicsView{background-color:transparent;}");
|
||||
mGraView->setScene(mScene);
|
||||
qreal scale = qMin(mGraView->width() / mScene->width(), mGraView->height() / mScene->height());
|
||||
mGraView->scale(scale, scale);
|
||||
hBox->addWidget(mGraView);
|
||||
grid->addWidget(mGraView, 0, 1);
|
||||
|
||||
auto vBox = new VBox(hBox);
|
||||
vBox->addWidget(fdIdx = new QLabel, 0, Qt::AlignCenter);
|
||||
if(listWidget()->count()>4) fdIdx->setNum(listWidget()->count());
|
||||
auto hBox = new HBox;
|
||||
hBox->setSpacing(4);
|
||||
grid->addLayout(hBox, 1, 1);
|
||||
grid->setColumnStretch(2, 1);
|
||||
grid->setRowStretch(2, 1);
|
||||
|
||||
auto hh = new HBox(vBox);
|
||||
hh->addStretch();
|
||||
fdPlayTimes = new QLabel(QString::number(mAttr["repeat"].toInt()));
|
||||
hh->addWidget(fdPlayTimes);
|
||||
hh->addWidget(new QLabel(tr("times")));
|
||||
hBox->addWidget(fdPlayTimes = new QLabel(QString::number(mAttr["repeat"].toInt())));
|
||||
gFont(fdPlayTimes, 12);
|
||||
|
||||
vBox->addStretch();
|
||||
auto fdTimes = new QLabel(tr("times"));
|
||||
gFont(fdTimes, 12);
|
||||
hBox->addWidget(fdTimes);
|
||||
hBox->addStretch();
|
||||
|
||||
return wgtPage;
|
||||
}
|
||||
|
|
|
@ -26,6 +26,8 @@ public:
|
|||
QGraphicsScene *mScene{0};
|
||||
QGraphicsView *mGraView{0};
|
||||
QLabel *fdIdx{0}, *fdPlayTimes{0};
|
||||
qreal scale{1};
|
||||
int viewW{120}, viewH{80};
|
||||
};
|
||||
|
||||
struct AudioInfo {
|
||||
|
|
Loading…
Reference in New Issue
Block a user