a4cc39fb10
* Don't include <QtGui>, which is a leftover from Qt4 and causes literally everything to be pulled into the TU. * Use forward declarations instead of includes where possible. * Replace aggregated Ui* classes with aggregation via pointer, which allows these classes to be forward-declared and thus further reduce the number of included headers. Aggregation via pointer has been the default in Qt Creator for some time now. * Fix minor warnings reported by Clang. * Move QnCheckBoxedHeaderView to a separate file. * Move QtvCodecInfo to a separate file, change initializer list to inline member initialization. * Create an actual QMake .pro file instead of stuffing it in MXE build scripts. * Fix 32-bit integers being used as pointers to QtvCodecInfo objects in 64-bit Windows builds. * Update information in the "About" tab.
77 lines
2.0 KiB
C++
77 lines
2.0 KiB
C++
#include "checkboxedheaderview.h"
|
|
|
|
#include <QPainter>
|
|
|
|
QnCheckBoxedHeaderView::QnCheckBoxedHeaderView(QWidget *parent)
|
|
: base_type(Qt::Horizontal, parent), m_checkState(Qt::Unchecked),
|
|
m_checkColumnIndex(0) {
|
|
connect(this, &QnCheckBoxedHeaderView::sectionClicked, this,
|
|
&QnCheckBoxedHeaderView::at_sectionClicked);
|
|
}
|
|
|
|
void QnCheckBoxedHeaderView::setCheckState(Qt::CheckState state) {
|
|
if (state == m_checkState)
|
|
return;
|
|
m_checkState = state;
|
|
emit checkStateChanged(state);
|
|
|
|
viewport()->update();
|
|
}
|
|
|
|
void QnCheckBoxedHeaderView::paintSection(QPainter *painter, const QRect &rect,
|
|
int logicalIndex) const {
|
|
painter->save();
|
|
base_type::paintSection(painter, rect, logicalIndex);
|
|
painter->restore();
|
|
|
|
if (logicalIndex == m_checkColumnIndex) {
|
|
|
|
if (!rect.isValid())
|
|
return;
|
|
QStyleOptionButton opt;
|
|
opt.initFrom(this);
|
|
|
|
QStyle::State state = QStyle::State_Raised;
|
|
if (isEnabled())
|
|
state |= QStyle::State_Enabled;
|
|
if (window()->isActiveWindow())
|
|
state |= QStyle::State_Active;
|
|
|
|
switch (m_checkState) {
|
|
case Qt::Checked:
|
|
state |= QStyle::State_On;
|
|
break;
|
|
case Qt::Unchecked:
|
|
state |= QStyle::State_Off;
|
|
break;
|
|
default:
|
|
state |= QStyle::State_NoChange;
|
|
break;
|
|
}
|
|
|
|
opt.rect = rect.adjusted(4, 0, 0, 0);
|
|
opt.state |= state;
|
|
opt.text = QString();
|
|
painter->save();
|
|
style()->drawControl(QStyle::CE_CheckBox, &opt, painter, this);
|
|
painter->restore();
|
|
}
|
|
}
|
|
|
|
QSize QnCheckBoxedHeaderView::sectionSizeFromContents(int logicalIndex) const {
|
|
QSize size = base_type::sectionSizeFromContents(logicalIndex);
|
|
if (logicalIndex != m_checkColumnIndex)
|
|
return size;
|
|
size.setWidth(15);
|
|
return size;
|
|
}
|
|
|
|
void QnCheckBoxedHeaderView::at_sectionClicked(int logicalIndex) {
|
|
if (logicalIndex != m_checkColumnIndex)
|
|
return;
|
|
if (m_checkState != Qt::Checked)
|
|
setCheckState(Qt::Checked);
|
|
else
|
|
setCheckState(Qt::Unchecked);
|
|
}
|