summaryrefslogtreecommitdiff
path: root/utils/regtools/qeditor/utils.h
diff options
context:
space:
mode:
Diffstat (limited to 'utils/regtools/qeditor/utils.h')
-rw-r--r--utils/regtools/qeditor/utils.h82
1 files changed, 66 insertions, 16 deletions
diff --git a/utils/regtools/qeditor/utils.h b/utils/regtools/qeditor/utils.h
index c78b0a40e4..078f3a85d7 100644
--- a/utils/regtools/qeditor/utils.h
+++ b/utils/regtools/qeditor/utils.h
@@ -37,6 +37,7 @@
37#include <QStyledItemDelegate> 37#include <QStyledItemDelegate>
38#include <QComboBox> 38#include <QComboBox>
39#include <QFileDialog> 39#include <QFileDialog>
40#include <QScrollBar>
40#include "settings.h" 41#include "settings.h"
41#include "backend.h" 42#include "backend.h"
42 43
@@ -292,28 +293,77 @@ protected:
292 bool m_read_only; 293 bool m_read_only;
293}; 294};
294 295
295class RegSexyDisplay : public QWidget 296class RegSexyDisplay2 : public QAbstractItemView
296{ 297{
297 Q_OBJECT 298 Q_OBJECT
298public: 299public:
299 RegSexyDisplay(const SocRegRef& reg, QWidget *parent = 0); 300 RegSexyDisplay2(QWidget *parent = 0);
301 virtual QModelIndex indexAt(const QPoint& point) const;
302 virtual void scrollTo(const QModelIndex& index, ScrollHint hint = EnsureVisible);
303 virtual QRect visualRect(const QModelIndex& index ) const;
304 virtual void setModel(QAbstractItemModel *model);
300 305
301 QSize minimumSizeHint() const; 306protected slots:
302 QSize sizeHint() const; 307 virtual void dataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight);
308 virtual void rowsInserted(const QModelIndex &parent, int start, int end);
309 virtual void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end);
310 virtual void scrollContentsBy(int dx, int dy);
311 virtual void updateGeometries();
303 312
304protected: 313protected:
305 int marginSize() const; 314 int GetMarginSize() const; // margin in cells
306 int separatorSize() const; 315 int GetSeparatorSize() const; // size of lines betweens cells
307 int columnWidth() const; 316 int GetColumnWidth() const; // width of a 1-bit column (excluding separators)
308 int headerHeight() const; 317 int GetHeaderHeight() const; // height of the header (excluding separators)
309 int gapHeight() const; 318 int GetGapHeight() const; // height of gap between header and fields
310 int maxContentHeight() const; 319 int GetMaxContentHeight() const; // maximum height of field columns
311 int textSep() const; 320 int GetHeaderTextSep() const; // height between digits in header
312 void paintEvent(QPaintEvent *event); 321 void RecomputeGeometry();
313 322
314private: 323 virtual bool isIndexHidden(const QModelIndex& index) const;
315 SocRegRef m_reg; 324 virtual QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers);
316 mutable QSize m_size; 325 virtual void setSelection(const QRect& rect, QItemSelectionModel::SelectionFlags flags);
326 virtual int verticalOffset() const;
327 virtual int horizontalOffset() const;
328 virtual QRegion visualRegionForSelection(const QItemSelection& selection) const;
329 virtual void paintEvent(QPaintEvent *event);
330 virtual void resizeEvent(QResizeEvent* event);
331
332 bool m_is_dirty;
333 int m_minimum_width, m_minimum_height;
334};
335
336/**
337 * The Qt designers chose to make QAbstractItemView a QAbstractScrollArea, so
338 * that the table scrolls when it doesn't fit. This might be a problem when
339 * one wants to put several tables on top of another, and the whole set into a
340 * big scrollable area, because QAbstractScrollArea provides dummy values as
341 * (minimum) size hints...So the big scroll area has no way of knowing the actual
342 * size of the widget inside and it ends being a scrollable table inside another
343 * scrollable, which is just super weird.
344 * The Unscroll<T> class provides a workaround this behaviour: it expects T
345 * to derive from QAbstractScrollArea and provides correct (minimum) size hints,
346 * based on the value of the scroll bars.
347 */
348template<typename T>
349class Unscroll : public T
350{
351public:
352 Unscroll(QWidget *parent = 0):T(parent) {}
353 virtual QSize sizeHint() const
354 {
355 QScrollBar *hsb = this->horizontalScrollBar();
356 QScrollBar *vsb = this->verticalScrollBar();
357 int w = hsb->maximum() - hsb->minimum() + hsb->pageStep();
358 int h = vsb->maximum() - vsb->minimum() + vsb->pageStep();
359 QMargins m = this->contentsMargins();
360 return QSize(m.left() + w + m.right(), m.top() + h + m.bottom());
361 }
362
363 virtual QSize minimumSizeHint() const
364 {
365 return sizeHint();
366 }
317}; 367};
318 368
319class GrowingTableView : public QTableView 369class GrowingTableView : public QTableView