65 setSelectionBehavior(QAbstractItemView::SelectItems);
66 setSelectionMode(QAbstractItemView::NoSelection);
68 setStyleSheet(
"QTableView{ border: 0px}");
69 setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
70 setEditTriggers(QAbstractItemView::NoEditTriggers);
76 QScrollerProperties props;
77 props.setScrollMetric(QScrollerProperties::VerticalOvershootPolicy,
78 QScrollerProperties::OvershootAlwaysOff);
79 props.setScrollMetric(QScrollerProperties::HorizontalOvershootPolicy,
80 QScrollerProperties::OvershootAlwaysOff);
81 scroller->setScrollerProperties(props);
83 SIGNAL(stateChanged(QScroller::State)),
108 const KConfigGroup cfg = KSharedConfig::openConfig()->group(
"advancedColorSelector");
110 m_d->numCols = cfg.readEntry(
m_d->configPrefix +
"NumCols", 1);
111 m_d->numRows = cfg.readEntry(
m_d->configPrefix +
"NumRows", 1);
113 m_d->patchWidth = cfg.readEntry(
m_d->configPrefix +
"Width", 20);
114 m_d->patchHeight = cfg.readEntry(
m_d->configPrefix +
"Height", 20);
115 if (cfg.readEntry(
m_d->configPrefix +
"Alignment",
false)) {
120 m_d->patchCount = cfg.readEntry(
m_d->configPrefix +
"Count", 15);
121 const bool allowScrolling = cfg.readEntry(
m_d->configPrefix +
"Scrolling",
true);
122 if (!allowScrolling) {
123 QScroller::scroller(
this)->ungrabGesture(
this);
124 horizontalScrollBar()->setEnabled(
false);
125 verticalScrollBar()->setEnabled(
false);
126 m_d->wasScrollingDisabled =
true;
127 }
else if (
m_d->wasScrollingDisabled) {
128 QScroller *scroller = QScroller::scroller(
this);
130 horizontalScrollBar()->setEnabled(
true);
131 verticalScrollBar()->setEnabled(
true);
132 m_d->wasScrollingDisabled =
false;
135 m_d->model.reset(
new QStandardItemModel(
m_d->numRows,
m_d->numCols,
this));
138 setMinimumWidth((
m_d->patchWidth + 0) *
m_d->numCols);
139 setMaximumWidth((
m_d->patchWidth + 0) *
m_d->numCols);
142 setMinimumHeight(
m_d->patchHeight);
143 setMaximumHeight(QWIDGETSIZE_MAX);
145 setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Ignored);
147 setMinimumHeight((
m_d->patchHeight + 0) *
m_d->numRows);
148 setMaximumHeight((
m_d->patchHeight + 0) *
m_d->numRows);
151 setMinimumWidth(
m_d->patchWidth);
152 setMaximumWidth(QWIDGETSIZE_MAX);
154 setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed);
158 verticalHeader()->setMinimumSectionSize(
m_d->patchHeight);
159 verticalHeader()->setMaximumSectionSize(
m_d->patchHeight);
160 verticalHeader()->setDefaultSectionSize(
m_d->patchHeight);
161 horizontalHeader()->setMinimumSectionSize(
m_d->patchWidth);
162 horizontalHeader()->setMaximumSectionSize(
m_d->patchWidth);
163 horizontalHeader()->setDefaultSectionSize(
m_d->patchWidth);
166 verticalHeader()->setSectionResizeMode(QHeaderView::Fixed);
167 horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed);
169 verticalHeader()->hide();
170 horizontalHeader()->hide();
172 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
173 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
175 setModel(
m_d->model.data());
206 bool horizontal = qAbs(event->angleDelta().x()) > qAbs(event->angleDelta().y());
209 QPoint modifiedAngleDelta = {
event->angleDelta().y(),
event->angleDelta().x()};
210 QWheelEvent modifiedEvent(event->position(),
211 event->globalPosition(),
218 horizontalScrollBar()->event(&modifiedEvent);
223 QTableView::wheelEvent(event);
240 if (
m_d->colorPatches.isEmpty()) {
251 int index = 1 % limit;
253 Q_FOREACH (
const KoColor &color,
m_d->colorPatches) {
254 if (linearIndex >
m_d->patchCount) {
264 m_d->model->insertRow(pointer);
266 m_d->model->insertColumn(pointer);
269 QStandardItem *item =
new QStandardItem;
270 item->setData(QVariant(), Qt::DisplayRole);
271 item->setData(color.
toQColor(), Qt::UserRole);
273 m_d->model->setItem(pointer, index, item);
275 m_d->model->setItem(index, pointer, item);
277 index = (index + 1) % limit;
285 const QModelIndex index = indexAt(mapFromGlobal(pos));
286 if (!index.isValid()) {
291 linearIndex = index.row() *
m_d->model->columnCount() + index.column();
293 linearIndex = index.column() *
m_d->model->rowCount() + index.row();
298 if (linearIndex < 0 || linearIndex >=
m_d->colorPatches.size()) {
301 return m_d->colorPatches[linearIndex];