added custom ColorLineEdit for the colors

master
adrido 2015-06-03 04:42:10 +02:00
parent 1905455c48
commit c6db7a264b
6 changed files with 238 additions and 100 deletions

View File

@ -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

81
colorlineedit.cpp Normal file
View File

@ -0,0 +1,81 @@
#include "colorlineedit.h"
#include <QToolButton>
#include <QStyle>
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;
}

33
colorlineedit.h Normal file
View File

@ -0,0 +1,33 @@
#ifndef COLORLINEEDIT_H
#define COLORLINEEDIT_H
#include <QLineEdit>
#include <QPushButton>
#include <QColorDialog>
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

View File

@ -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()
{

View File

@ -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();

View File

@ -797,7 +797,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>346</width>
<width>500</width>
<height>360</height>
</rect>
</property>
@ -1064,7 +1064,7 @@
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="bgcolor">
<widget class="ColorLineEdit" name="bgcolor">
<property name="statusTip">
<string>Specify the background color for the image</string>
</property>
@ -1098,7 +1098,7 @@
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="blockcolor">
<widget class="ColorLineEdit" name="blockcolor">
<property name="statusTip">
<string>Specify the color for empty mapblocks</string>
</property>
@ -1226,7 +1226,7 @@
</widget>
</item>
<item row="6" column="1">
<widget class="QLineEdit" name="tilebordercolor">
<widget class="ColorLineEdit" name="tilebordercolor">
<property name="statusTip">
<string>Specify the color for drawing tile borders</string>
</property>
@ -1236,7 +1236,7 @@
</widget>
</item>
<item row="5" column="1">
<widget class="QLineEdit" name="playercolor">
<widget class="ColorLineEdit" name="playercolor">
<property name="statusTip">
<string>Specify the color for drawing player locations</string>
</property>
@ -1246,7 +1246,7 @@
</widget>
</item>
<item row="4" column="1">
<widget class="QLineEdit" name="origincolor">
<widget class="ColorLineEdit" name="origincolor">
<property name="statusTip">
<string> Specify the color for drawing the map origin (0,0)</string>
</property>
@ -1256,7 +1256,7 @@
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="scalecolor">
<widget class="ColorLineEdit" name="scalecolor">
<property name="statusTip">
<string> Specify the color for text in the scales on the side</string>
</property>
@ -1848,7 +1848,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>343</width>
<width>500</width>
<height>261</height>
</rect>
</property>
@ -2399,6 +2399,16 @@ p, li { white-space: pre-wrap; }
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
<customwidget>
<class>ColorLineEdit</class>
<extends>QLineEdit</extends>
<header>colorlineedit.h</header>
<slots>
<slot>selectColor()</slot>
</slots>
</customwidget>
</customwidgets>
<resources>
<include location="minetestmappergui.qrc"/>
</resources>
@ -2414,8 +2424,8 @@ p, li { white-space: pre-wrap; }
<y>-1</y>
</hint>
<hint type="destinationlabel">
<x>207</x>
<y>530</y>
<x>217</x>
<y>393</y>
</hint>
</hints>
</connection>
@ -2650,8 +2660,8 @@ p, li { white-space: pre-wrap; }
<slot>selectAll()</slot>
<hints>
<hint type="sourcelabel">
<x>135</x>
<y>485</y>
<x>147</x>
<y>348</y>
</hint>
<hint type="destinationlabel">
<x>121</x>
@ -2699,7 +2709,7 @@ p, li { white-space: pre-wrap; }
<hints>
<hint type="sourcelabel">
<x>363</x>
<y>485</y>
<y>348</y>
</hint>
<hint type="destinationlabel">
<x>332</x>
@ -2715,7 +2725,7 @@ p, li { white-space: pre-wrap; }
<hints>
<hint type="sourcelabel">
<x>537</x>
<y>485</y>
<y>348</y>
</hint>
<hint type="destinationlabel">
<x>424</x>
@ -2723,5 +2733,101 @@ p, li { white-space: pre-wrap; }
</hint>
</hints>
</connection>
<connection>
<sender>selectBgColor</sender>
<signal>clicked()</signal>
<receiver>bgcolor</receiver>
<slot>selectColor()</slot>
<hints>
<hint type="sourcelabel">
<x>484</x>
<y>135</y>
</hint>
<hint type="destinationlabel">
<x>430</x>
<y>138</y>
</hint>
</hints>
</connection>
<connection>
<sender>selectBlockColor</sender>
<signal>clicked()</signal>
<receiver>blockcolor</receiver>
<slot>selectColor()</slot>
<hints>
<hint type="sourcelabel">
<x>470</x>
<y>169</y>
</hint>
<hint type="destinationlabel">
<x>441</x>
<y>169</y>
</hint>
</hints>
</connection>
<connection>
<sender>selectScaleColor</sender>
<signal>clicked()</signal>
<receiver>scalecolor</receiver>
<slot>selectColor()</slot>
<hints>
<hint type="sourcelabel">
<x>473</x>
<y>196</y>
</hint>
<hint type="destinationlabel">
<x>431</x>
<y>197</y>
</hint>
</hints>
</connection>
<connection>
<sender>selectOriginColor</sender>
<signal>clicked()</signal>
<receiver>origincolor</receiver>
<slot>selectAll()</slot>
<hints>
<hint type="sourcelabel">
<x>463</x>
<y>227</y>
</hint>
<hint type="destinationlabel">
<x>441</x>
<y>227</y>
</hint>
</hints>
</connection>
<connection>
<sender>selectPlayerColor</sender>
<signal>clicked()</signal>
<receiver>playercolor</receiver>
<slot>selectColor()</slot>
<hints>
<hint type="sourcelabel">
<x>475</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>439</x>
<y>259</y>
</hint>
</hints>
</connection>
<connection>
<sender>selectTileBorderColor</sender>
<signal>clicked()</signal>
<receiver>tilebordercolor</receiver>
<slot>selectColor()</slot>
<hints>
<hint type="sourcelabel">
<x>464</x>
<y>283</y>
</hint>
<hint type="destinationlabel">
<x>431</x>
<y>285</y>
</hint>
</hints>
</connection>
</connections>
</ui>