List of all members.
Constructor & Destructor Documentation
ColorPickerPopup::ColorPickerPopup |
( |
int |
width, |
|
|
bool |
withColorDialog, |
|
|
QWidget * |
parent = 0 | |
|
) |
| | |
: QFrame(parent, Qt::Popup)
{
setFrameStyle(QFrame::StyledPanel);
setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
setFocusPolicy(Qt::StrongFocus);
setMouseTracking(true);
cols = width;
if (withColorDialog) {
moreButton = new ColorPickerButton(this);
moreButton->setFixedWidth(24);
moreButton->setFixedHeight(21);
moreButton->setFrameRect(QRect(2, 2, 20, 17));
connect(moreButton, SIGNAL(clicked()), SLOT(getColorFromDialog()));
} else {
moreButton = 0;
}
eventLoop = 0;
grid = 0;
regenerateGrid();
}
ColorPickerPopup::~ColorPickerPopup |
( |
|
) |
|
{
if (eventLoop)
eventLoop->exit();
}
Member Function Documentation
QColor ColorPickerPopup::color |
( |
int |
index |
) |
const |
void ColorPickerPopup::exec |
( |
|
) |
|
void ColorPickerPopup::getColorFromDialog |
( |
|
) |
[slot] |
void ColorPickerPopup::hid |
( |
|
) |
[signal] |
void ColorPickerPopup::hideEvent |
( |
QHideEvent * |
e |
) |
[protected] |
void ColorPickerPopup::insertColor |
( |
const QColor & |
col, |
|
|
const QString & |
text, |
|
|
int |
index | |
|
) |
| | |
void ColorPickerPopup::keyPressEvent |
( |
QKeyEvent * |
e |
) |
[protected] |
{
int curRow = 0;
int curCol = 0;
bool foundFocus = false;
for (int j = 0; !foundFocus && j < grid->rowCount(); ++j) {
for (int i = 0; !foundFocus && i < grid->columnCount(); ++i) {
if (widgetAt[j][i] && widgetAt[j][i]->hasFocus()) {
curRow = j;
curCol = i;
foundFocus = true;
break;
}
}
}
switch (e->key()) {
case Qt::Key_Left:
if (curCol > 0) --curCol;
else if (curRow > 0) { --curRow; curCol = grid->columnCount() - 1; }
break;
case Qt::Key_Right:
if (curCol < grid->columnCount() - 1 && widgetAt[curRow][curCol + 1]) ++curCol;
else if (curRow < grid->rowCount() - 1) { ++curRow; curCol = 0; }
break;
case Qt::Key_Up:
if (curRow > 0) --curRow;
else curCol = 0;
break;
case Qt::Key_Down:
if (curRow < grid->rowCount() - 1) {
QWidget *w = widgetAt[curRow + 1][curCol];
if (w) {
++curRow;
} else for (int i = 1; i < grid->columnCount(); ++i) {
if (!widgetAt[curRow + 1][i]) {
curCol = i - 1;
++curRow;
break;
}
}
}
break;
case Qt::Key_Space:
case Qt::Key_Return:
case Qt::Key_Enter: {
QWidget *w = widgetAt[curRow][curCol];
if (w && w->inherits("ColorPickerItem")) {
ColorPickerItem *wi = reinterpret_cast<ColorPickerItem *>(w);
wi->setSelected(true);
QLayoutItem *layoutItem;
int i = 0;
while ((layoutItem = grid->itemAt(i)) != 0) {
QWidget *w = layoutItem->widget();
if (w && w->inherits("ColorPickerItem")) {
ColorPickerItem *litem
= reinterpret_cast<ColorPickerItem *>(layoutItem->widget());
if (litem != wi)
litem->setSelected(false);
}
++i;
}
lastSel = wi->color();
emit selected(wi->color());
hide();
} else if (w && w->inherits("QPushButton")) {
ColorPickerItem *wi = reinterpret_cast<ColorPickerItem *>(w);
wi->setSelected(true);
QLayoutItem *layoutItem;
int i = 0;
while ((layoutItem = grid->itemAt(i)) != 0) {
QWidget *w = layoutItem->widget();
if (w && w->inherits("ColorPickerItem")) {
ColorPickerItem *litem
= reinterpret_cast<ColorPickerItem *>(layoutItem->widget());
if (litem != wi)
litem->setSelected(false);
}
++i;
}
lastSel = wi->color();
emit selected(wi->color());
hide();
}
}
break;
case Qt::Key_Escape:
hide();
break;
default:
e->ignore();
break;
}
widgetAt[curRow][curCol]->setFocus();
}
QColor ColorPickerPopup::lastSelected |
( |
|
) |
const |
void ColorPickerPopup::mouseReleaseEvent |
( |
QMouseEvent * |
e |
) |
[protected] |
{
if (!rect().contains(e->pos()))
hide();
}
void ColorPickerPopup::regenerateGrid |
( |
|
) |
[protected] |
Referenced by ColorPickerPopup(), and insertColor().
{
widgetAt.clear();
int columns = cols;
if (columns == -1)
columns = (int) ceil(sqrt((float) items.count()));
if (grid) delete grid;
grid = new QGridLayout(this);
grid->setMargin(1);
grid->setSpacing(0);
int ccol = 0, crow = 0;
for (int i = 0; i < items.size(); ++i) {
if (items.at(i)) {
widgetAt[crow][ccol] = items.at(i);
grid->addWidget(items.at(i), crow, ccol++);
if (ccol == columns) {
++crow;
ccol = 0;
}
}
}
if (moreButton) {
grid->addWidget(moreButton, crow, ccol);
widgetAt[crow][ccol] = moreButton;
}
updateGeometry();
}
void ColorPickerPopup::selected |
( |
const QColor & |
|
) |
[signal] |
void ColorPickerPopup::setExecFlag |
( |
|
) |
|
void ColorPickerPopup::showEvent |
( |
QShowEvent * |
e |
) |
[protected] |
{
bool foundSelected = false;
for (int i = 0; i < grid->columnCount(); ++i) {
for (int j = 0; j < grid->rowCount(); ++j) {
QWidget *w = widgetAt[j][i];
if (w && w->inherits("ColorPickerItem")) {
if (((ColorPickerItem *)w)->isSelected()) {
w->setFocus();
foundSelected = true;
break;
}
}
}
}
if (!foundSelected) {
if (items.count() == 0)
setFocus();
else
widgetAt[0][0]->setFocus();
}
}
void ColorPickerPopup::updateSelected |
( |
|
) |
[protected, slot] |
The documentation for this class was generated from the following file: