propertiesdialog.cpp

来自「QT4 gui programming的随书光盘」· C++ 代码 · 共 66 行

CPP
66
字号
#include <QtGui>#include "node.h"#include "propertiesdialog.h"PropertiesDialog::PropertiesDialog(Node *node, QWidget *parent)    : QDialog(parent){    setupUi(this);    this->node = node;    xSpinBox->setValue(int(node->x()));    ySpinBox->setValue(int(node->y()));    textLineEdit->setText(node->text());    textColor = node->textColor();    outlineColor = node->outlineColor();    backgroundColor = node->backgroundColor();    updateColorLabel(outlineColorLabel, outlineColor);    updateColorLabel(backgroundColorLabel, backgroundColor);    updateColorLabel(textColorLabel, textColor);}void PropertiesDialog::on_buttonBox_accepted(){    node->setPos(xSpinBox->value(), ySpinBox->value());    node->setText(textLineEdit->text());    node->setOutlineColor(outlineColor);    node->setBackgroundColor(backgroundColor);    node->setTextColor(textColor);    node->update();    QDialog::accept();}void PropertiesDialog::on_textColorButton_clicked(){    chooseColor(textColorLabel, &textColor);}void PropertiesDialog::on_outlineColorButton_clicked(){    chooseColor(outlineColorLabel, &outlineColor);}void PropertiesDialog::on_backgroundColorButton_clicked(){    chooseColor(backgroundColorLabel, &backgroundColor);}void PropertiesDialog::updateColorLabel(QLabel *label,                                        const QColor &color){    QPixmap pixmap(16, 16);    pixmap.fill(color);    label->setPixmap(pixmap);}void PropertiesDialog::chooseColor(QLabel *label, QColor *color){    QColor newColor = QColorDialog::getColor(*color, this);    if (newColor.isValid()) {        *color = newColor;        updateColorLabel(label, *color);    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?