diff --git a/MinetestMapperGui.pro b/MinetestMapperGui.pro index 007391d..6bc7a51 100644 --- a/MinetestMapperGui.pro +++ b/MinetestMapperGui.pro @@ -14,9 +14,11 @@ TEMPLATE = app SOURCES += main.cpp\ - mainwindow.cpp + mainwindow.cpp \ + colorlineedit.cpp -HEADERS += mainwindow.h +HEADERS += mainwindow.h \ + colorlineedit.h FORMS += mainwindow.ui diff --git a/colorlineedit.cpp b/colorlineedit.cpp new file mode 100644 index 0000000..430b2a8 --- /dev/null +++ b/colorlineedit.cpp @@ -0,0 +1,81 @@ +#include "colorlineedit.h" + +#include +#include + +ColorLineEdit::ColorLineEdit(QWidget *parent) : + QLineEdit(parent) +{ + // Create the search button and set its icon, cursor, and stylesheet + this->mColorButton = new QToolButton(this); + this->mColorButton->setFixedSize(20,20); + this->mColorButton->setCursor(Qt::PointingHandCursor); + this->mColorButton->setStyleSheet(this->buttonStyleSheetForCurrentState()); + + // Update the search button when the text changes + QObject::connect(this, SIGNAL(textChanged(QString)), SLOT(updateColorButton(QString))); + QObject::connect(this->mColorButton,SIGNAL(clicked(bool)), SLOT(selectColor())); + // Some stylesheet and size corrections for the text box + //this->setPlaceholderText(tr("Search")); + //this->setStyleSheet(this->styleSheetForCurrentState()); + + int frameWidth = this->style()->pixelMetric(QStyle::PM_DefaultFrameWidth); + QSize minSizeHint = this->minimumSizeHint(); + this->setMinimumSize(qMax(minSizeHint.width(), this->mColorButton->sizeHint().width() + frameWidth * 2 + 2), + qMax(minSizeHint.height(), this->mColorButton->sizeHint().height() + frameWidth * 2+2)); +} + +void ColorLineEdit::resizeEvent(QResizeEvent *event) +{ + Q_UNUSED(event); + QSize size = this->mColorButton->sizeHint(); + int frameWidth = this->style()->pixelMetric(QStyle::PM_DefaultFrameWidth); + this->mColorButton->move(this->rect().right() - frameWidth - size.width() - 2, (this->rect().bottom() + 2 - size.height()) / 2); +} +void ColorLineEdit::selectColor() +{ + const QColorDialog::ColorDialogOptions options = QFlag(QColorDialog::DontUseNativeDialog); + const QColor color = QColorDialog::getColor(this->text(), this, tr("select color"),options); + + if (color.isValid()) { + this->setText(color.name()); + } +} + +void ColorLineEdit::updateColorButton(const QString &text) +{ + const QColor color = QColor(text); + if (color.isValid()) + { + // We have some text in the box - set the button to clear the text + QPixmap pixmap(this->height(),this->height()); + pixmap.fill(color); + QIcon icon(pixmap); + this->mColorButton->setIcon(icon); + } + else + { + // The text box is empty - make the icon do nothing when clicked + QIcon icon(":/color"); + this->mColorButton->setIcon(icon); + } + + //this->mColorButton->setStyleSheet(this->buttonStyleSheetForCurrentState()); +} + + +QString ColorLineEdit::buttonStyleSheetForCurrentState() const +{ + QString style; + style += "QToolButton {"; + style += "border: 1px solid black; margin: 0; padding: 0;"; + style += "}"; + + /*if (!this->text().isEmpty()) + { + style += "QToolButton:hover { background-image: url(:/images/esf-clear-hover.png); }"; + style += "QToolButton:pressed { background-image: url(:/images/esf-clear-active.png); }"; + }*/ + + return style; +} diff --git a/colorlineedit.h b/colorlineedit.h new file mode 100644 index 0000000..9cab5c9 --- /dev/null +++ b/colorlineedit.h @@ -0,0 +1,33 @@ +#ifndef COLORLINEEDIT_H +#define COLORLINEEDIT_H +#include +#include +#include + +class QToolButton; + +class ColorLineEdit : public QLineEdit +{ + Q_OBJECT + +public: + explicit ColorLineEdit(QWidget *parent = NULL); + +public slots: + void selectColor(); + +protected: + void resizeEvent(QResizeEvent *event); + +private slots: + void updateColorButton(const QString &text); + +private: + //QString styleSheetForCurrentState() const; + QString buttonStyleSheetForCurrentState() const; + + QToolButton *mColorButton; +}; + + +#endif // COLORLINEEDIT_H diff --git a/mainwindow.cpp b/mainwindow.cpp index 71fe720..6f64518 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -793,78 +793,6 @@ void MainWindow::on_browseColorsTxt_clicked() if(fileName!="") ui->path_ColorsTxt->setText(fileName); } -void MainWindow::on_selectBgColor_clicked() -{ - const QColorDialog::ColorDialogOptions options = QFlag(QColorDialog::DontUseNativeDialog); - const QColor color = QColorDialog::getColor(ui->bgcolor->text(), this, tr("select color"),options); - - if (color.isValid()) { - ui->bgcolor->setText(color.name()); - ui->bgcolor->setPalette(QPalette(color)); - //ui->lineEdit_bgcolor->setAutoFillBackground(true); - } -} - -void MainWindow::on_selectBlockColor_clicked() -{ - const QColorDialog::ColorDialogOptions options = QFlag(QColorDialog::DontUseNativeDialog); - const QColor color = QColorDialog::getColor(ui->blockcolor->text(), this, tr("select color"),options); - - if (color.isValid()) { - ui->blockcolor->setText(color.name()); - ui->blockcolor->setPalette(QPalette(color)); - //ui->lineEdit_bgcolor->setAutoFillBackground(true); - } -} - -void MainWindow::on_selectScaleColor_clicked() -{ - const QColorDialog::ColorDialogOptions options = QFlag(QColorDialog::DontUseNativeDialog); - const QColor color = QColorDialog::getColor(ui->scalecolor->text(), this, tr("select color"),options); - - if (color.isValid()) { - ui->scalecolor->setText(color.name()); - ui->scalecolor->setPalette(QPalette(color)); - //ui->lineEdit_bgcolor->setAutoFillBackground(true); - } -} - -void MainWindow::on_selectOriginColor_clicked() -{ - const QColorDialog::ColorDialogOptions options = QFlag(QColorDialog::DontUseNativeDialog); - const QColor color = QColorDialog::getColor(ui->origincolor->text(), this, tr("select color"),options); - - if (color.isValid()) { - ui->origincolor->setText(color.name()); - ui->origincolor->setPalette(QPalette(color)); - //ui->lineEdit_bgcolor->setAutoFillBackground(true); - } -} - - -void MainWindow::on_selectPlayerColor_clicked() -{ - const QColorDialog::ColorDialogOptions options = QFlag(QColorDialog::DontUseNativeDialog); - const QColor color = QColorDialog::getColor(ui->playercolor->text(), this, tr("select color"),options); - - if (color.isValid()) { - ui->playercolor->setText(color.name()); - ui->playercolor->setPalette(QPalette(color)); - //ui->lineEdit_bgcolor->setAutoFillBackground(true); - } -} - -void MainWindow::on_selectTileBorderColor_clicked() -{ - const QColorDialog::ColorDialogOptions options = QFlag(QColorDialog::DontUseNativeDialog); - const QColor color = QColorDialog::getColor(ui->tilebordercolor->text(), this, tr("select color"),options); - - if (color.isValid()) { - ui->tilebordercolor->setText(color.name()); - ui->tilebordercolor->setPalette(QPalette(color)); - //ui->lineEdit_bgcolor->setAutoFillBackground(true); - } -} void MainWindow::on_actionAbout_MinetestMapperGUI_triggered() { diff --git a/mainwindow.h b/mainwindow.h index 43ef9d1..c23a5c2 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -63,18 +63,6 @@ private slots: void on_browse_HeightmapColors_clicked(); - void on_selectBgColor_clicked(); - - void on_selectBlockColor_clicked(); - - void on_selectScaleColor_clicked(); - - void on_selectOriginColor_clicked(); - - void on_selectPlayerColor_clicked(); - - void on_selectTileBorderColor_clicked(); - void on_browseColorsTxt_clicked(); void on_actionAbout_MinetestMapperGUI_triggered(); diff --git a/mainwindow.ui b/mainwindow.ui index 1413192..69b11bc 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -797,7 +797,7 @@ 0 0 - 346 + 500 360 @@ -1064,7 +1064,7 @@ - + Specify the background color for the image @@ -1098,7 +1098,7 @@ - + Specify the color for empty mapblocks @@ -1226,7 +1226,7 @@ - + Specify the color for drawing tile borders @@ -1236,7 +1236,7 @@ - + Specify the color for drawing player locations @@ -1246,7 +1246,7 @@ - + Specify the color for drawing the map origin (0,0) @@ -1256,7 +1256,7 @@ - + Specify the color for text in the scales on the side @@ -1848,7 +1848,7 @@ 0 0 - 343 + 500 261 @@ -2399,6 +2399,16 @@ p, li { white-space: pre-wrap; } + + + ColorLineEdit + QLineEdit +
colorlineedit.h
+ + selectColor() + +
+
@@ -2414,8 +2424,8 @@ p, li { white-space: pre-wrap; } -1 - 207 - 530 + 217 + 393 @@ -2650,8 +2660,8 @@ p, li { white-space: pre-wrap; } selectAll() - 135 - 485 + 147 + 348 121 @@ -2699,7 +2709,7 @@ p, li { white-space: pre-wrap; } 363 - 485 + 348 332 @@ -2715,7 +2725,7 @@ p, li { white-space: pre-wrap; } 537 - 485 + 348 424 @@ -2723,5 +2733,101 @@ p, li { white-space: pre-wrap; } + + selectBgColor + clicked() + bgcolor + selectColor() + + + 484 + 135 + + + 430 + 138 + + + + + selectBlockColor + clicked() + blockcolor + selectColor() + + + 470 + 169 + + + 441 + 169 + + + + + selectScaleColor + clicked() + scalecolor + selectColor() + + + 473 + 196 + + + 431 + 197 + + + + + selectOriginColor + clicked() + origincolor + selectAll() + + + 463 + 227 + + + 441 + 227 + + + + + selectPlayerColor + clicked() + playercolor + selectColor() + + + 475 + 260 + + + 439 + 259 + + + + + selectTileBorderColor + clicked() + tilebordercolor + selectColor() + + + 464 + 283 + + + 431 + 285 + + +