**
****************************************************************************/
-#include <QPainter>
#include <QPaintEvent>
+#include <QPainter>
#include <QStyle>
#include <QStyleOptionFrame>
-#include "wellarray.h"
+#include "wellarray.hpp"
-void QWellArray::paintEvent(QPaintEvent *e)
+namespace pv {
+namespace widgets {
+
+void WellArray::paintEvent(QPaintEvent *event)
{
- QRect r = e->rect();
+ QRect r = event->rect();
int cx = r.x();
int cy = r.y();
int ch = r.height();
}
}
-struct QWellArrayData {
+struct WellArrayData {
QBrush *brush;
};
-QWellArray::QWellArray(int rows, int cols, QWidget *parent)
+WellArray::WellArray(int rows, int cols, QWidget *parent)
: QWidget(parent)
,nrows(rows), ncols(cols)
{
- d = 0;
+ d = nullptr;
setFocusPolicy(Qt::StrongFocus);
cellw = 28;
cellh = 24;
selRow = -1;
}
-QSize QWellArray::sizeHint() const
+QSize WellArray::sizeHint() const
{
ensurePolished();
return gridSize().boundedTo(QSize(640, 480));
}
-void QWellArray::paintCell(QPainter* p, int row, int col, const QRect &rect)
+void WellArray::paintCell(QPainter* p, int row, int col, const QRect &rect)
{
int b = 3; //margin
- const QPalette & g = palette();
+ const QPalette& g = palette();
QStyleOptionFrame opt;
int dfw = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
opt.lineWidth = dfw;
/*!
Reimplement this function to change the contents of the well array.
*/
-void QWellArray::paintCellContents(QPainter *p, int row, int col, const QRect &r)
+void WellArray::paintCellContents(QPainter *p, int row, int col, const QRect &r)
{
if (d) {
p->fillRect(r, d->brush[row*numCols()+col]);
}
}
-void QWellArray::mousePressEvent(QMouseEvent *e)
+void WellArray::mousePressEvent(QMouseEvent *event)
{
// The current cell marker is set to the cell the mouse is pressed in
- QPoint pos = e->pos();
+ QPoint pos = event->pos();
setCurrent(rowAt(pos.y()), columnAt(pos.x()));
}
-void QWellArray::mouseReleaseEvent(QMouseEvent * /* event */)
+void WellArray::mouseReleaseEvent(QMouseEvent * /* event */)
{
// The current cell marker is set to the cell the mouse is clicked in
setSelected(curRow, curCol);
the same as the currently selected cell.
*/
-void QWellArray::setCurrent(int row, int col)
+void WellArray::setCurrent(int row, int col)
{
if ((curRow == row) && (curCol == col))
return;
Does not set the position of the focus indicator.
*/
-void QWellArray::setSelected(int row, int col)
+void WellArray::setSelected(int row, int col)
{
int oldRow = selRow;
int oldCol = selCol;
updateCell(oldRow, oldCol);
updateCell(selRow, selCol);
if (row >= 0)
- emit selected(row, col);
+ selected(row, col);
}
-void QWellArray::focusInEvent(QFocusEvent*)
+void WellArray::focusInEvent(QFocusEvent*)
{
updateCell(curRow, curCol);
}
-void QWellArray::setCellBrush(int row, int col, const QBrush &b)
+void WellArray::setCellBrush(int row, int col, const QBrush &b)
{
if (!d) {
- d = new QWellArrayData;
+ d = new WellArrayData;
int i = numRows()*numCols();
d->brush = new QBrush[i];
}
set, Qt::NoBrush is returned.
*/
-QBrush QWellArray::cellBrush(int row, int col)
+QBrush WellArray::cellBrush(int row, int col)
{
if (d && row >= 0 && row < numRows() && col >= 0 && col < numCols())
return d->brush[row*numCols()+col];
/*!\reimp
*/
-void QWellArray::focusOutEvent(QFocusEvent*)
+void WellArray::focusOutEvent(QFocusEvent*)
{
updateCell(curRow, curCol);
}
/*\reimp
*/
-void QWellArray::keyPressEvent(QKeyEvent* e)
+void WellArray::keyPressEvent(QKeyEvent* event)
{
- switch(e->key()) { // Look at the key code
+ switch (event->key()) { // Look at the key code
case Qt::Key_Left: // If 'left arrow'-key,
- if(curCol > 0) // and cr't not in leftmost col
+ if (curCol > 0) // and cr't not in leftmost col
setCurrent(curRow, curCol - 1); // set cr't to next left column
break;
case Qt::Key_Right: // Correspondingly...
- if(curCol < numCols()-1)
+ if (curCol < numCols()-1)
setCurrent(curRow, curCol + 1);
break;
case Qt::Key_Up:
- if(curRow > 0)
+ if (curRow > 0)
setCurrent(curRow - 1, curCol);
break;
case Qt::Key_Down:
- if(curRow < numRows()-1)
+ if (curRow < numRows()-1)
setCurrent(curRow + 1, curCol);
break;
case Qt::Key_Space:
setSelected(curRow, curCol);
break;
default: // If not an interesting key,
- e->ignore(); // we don't accept the event
+ event->ignore(); // we don't accept the event
return;
}
}
+
+} // namespace widgets
+} // namespace pv