qtgradientstopseditor.cpp
来自「奇趣公司比较新的qt/emd版本」· C++ 代码 · 共 637 行 · 第 1/2 页
CPP
637 行
/******************************************************************************** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.**** This file is part of the Qt Designer of the Qt Toolkit.**** This file may be used under the terms of the GNU General Public** License version 2.0 as published by the Free Software Foundation** and appearing in the file LICENSE.GPL included in the packaging of** this file. Please review the following information to ensure GNU** General Public Licensing requirements will be met:** http://trolltech.com/products/qt/licenses/licensing/opensource/**** If you are unsure which license is appropriate for your use, please** review the following information:** http://trolltech.com/products/qt/licenses/licensing/licensingoverview** or contact the sales department at sales@trolltech.com.**** In addition, as a special exception, Trolltech gives you certain** additional rights. These rights are described in the Trolltech GPL** Exception version 1.0, which can be found at** http://www.trolltech.com/products/qt/gplexception/ and in the file** GPL_EXCEPTION.txt in this package.**** In addition, as a special exception, Trolltech, as the sole copyright** holder for Qt Designer, grants users of the Qt/Eclipse Integration** plug-in the right for the Qt/Eclipse Integration to link to** functionality provided by Qt Designer and its related libraries.**** Trolltech reserves all rights not expressly granted herein.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.******************************************************************************//*TRANSLATOR qdesigner_internal::QtGradientStopsEditor*/#include "qtgradientstopseditor.h"#include "ui_qtgradientstopseditor.h"#include "qtgradientstopsmodel.h"#include <QTimer>#include "qdebug.h"using namespace qdesigner_internal;namespace qdesigner_internal {class QtGradientStopsEditorPrivate{ QtGradientStopsEditor *q_ptr; Q_DECLARE_PUBLIC(QtGradientStopsEditor)public: void slotHsvClicked(); void slotRgbClicked(); void slotCurrentStopChanged(QtGradientStop *stop); void slotStopMoved(QtGradientStop *stop, qreal newPos); void slotStopChanged(QtGradientStop *stop, const QColor &newColor); void slotStopSelected(QtGradientStop *stop, bool selected); void slotStopAdded(QtGradientStop *stop); void slotStopRemoved(QtGradientStop *stop); void slotUpdatePositionSpinBox(); void slotChangeColor(const QColor &color); void slotChangeHue(const QColor &color); void slotChangeSaturation(const QColor &color); void slotChangeValue(const QColor &color); void slotChangeAlpha(const QColor &color); void slotChangeHue(int color); void slotChangeSaturation(int color); void slotChangeValue(int color); void slotChangeAlpha(int color); void slotChangePosition(); void slotChangeZoom(); void slotZoomIn(); void slotZoomOut(); void slotZoomAll(); void enableCurrent(bool enable); void setColorSpinBoxes(const QColor &color); QMap<qreal, QColor> stopsData(const QMap<qreal, QtGradientStop *> &stops) const; QGradientStops makeGradientStops(const QMap<qreal, QColor> &data) const; void updateZoom(); QtGradientStopsModel *m_model; Ui::QtGradientStopsEditor m_ui;};}void QtGradientStopsEditorPrivate::enableCurrent(bool enable){ m_ui.positionLabel->setEnabled(enable); m_ui.colorLabel->setEnabled(enable); m_ui.hueLabel->setEnabled(enable); m_ui.saturationLabel->setEnabled(enable); m_ui.valueLabel->setEnabled(enable); m_ui.alphaLabel->setEnabled(enable); m_ui.positionSpinBox->setEnabled(enable); m_ui.colorButton->setEnabled(enable); m_ui.hueColorLine->setEnabled(enable); m_ui.saturationColorLine->setEnabled(enable); m_ui.valueColorLine->setEnabled(enable); m_ui.alphaColorLine->setEnabled(enable); m_ui.hueSpinBox->setEnabled(enable); m_ui.saturationSpinBox->setEnabled(enable); m_ui.valueSpinBox->setEnabled(enable); m_ui.alphaSpinBox->setEnabled(enable);}QMap<qreal, QColor> QtGradientStopsEditorPrivate::stopsData(const QMap<qreal, QtGradientStop *> &stops) const{ QMap<qreal, QColor> data; QMap<qreal, QtGradientStop *>::ConstIterator itStop = stops.constBegin(); while (itStop != stops.constEnd()) { QtGradientStop *stop = itStop.value(); data[stop->position()] = stop->color(); itStop++; } return data;}QGradientStops QtGradientStopsEditorPrivate::makeGradientStops(const QMap<qreal, QColor> &data) const{ QGradientStops stops; QMap<qreal, QColor>::ConstIterator itData = data.constBegin(); while (itData != data.constEnd()) { stops << QPair<qreal, QColor>(itData.key(), itData.value()); itData++; } return stops;}void QtGradientStopsEditorPrivate::updateZoom(){ int zoom = qRound(m_ui.gradientWidget->zoom() * 100); bool zoomInEnabled = true; bool zoomOutEnabled = true; bool zoomAllEnabled = true; if (zoom <= 100) { zoomAllEnabled = false; zoomOutEnabled = false; } else if (zoom >= 10000) { zoomInEnabled = false; } m_ui.zoomInButton->setEnabled(zoomInEnabled); m_ui.zoomOutButton->setEnabled(zoomOutEnabled); m_ui.zoomAllButton->setEnabled(zoomAllEnabled);}void QtGradientStopsEditorPrivate::slotHsvClicked(){ m_ui.hueLabel->setText(QApplication::translate("qdesigner_internal::QtGradientStopsEditor", "Hue", 0, QApplication::UnicodeUTF8)); m_ui.saturationLabel->setText(QApplication::translate("qdesigner_internal::QtGradientStopsEditor", "Saturation", 0, QApplication::UnicodeUTF8)); m_ui.valueLabel->setText(QApplication::translate("qdesigner_internal::QtGradientStopsEditor", "Value", 0, QApplication::UnicodeUTF8)); m_ui.hueColorLine->setColorComponent(QtColorLine::Hue); m_ui.saturationColorLine->setColorComponent(QtColorLine::Saturation); m_ui.valueColorLine->setColorComponent(QtColorLine::Value); setColorSpinBoxes(m_ui.colorButton->color());}void QtGradientStopsEditorPrivate::slotRgbClicked(){ m_ui.hueLabel->setText(QApplication::translate("qdesigner_internal::QtGradientStopsEditor", "Red", 0, QApplication::UnicodeUTF8)); m_ui.saturationLabel->setText(QApplication::translate("qdesigner_internal::QtGradientStopsEditor", "Green", 0, QApplication::UnicodeUTF8)); m_ui.valueLabel->setText(QApplication::translate("qdesigner_internal::QtGradientStopsEditor", "Blue", 0, QApplication::UnicodeUTF8)); m_ui.hueColorLine->setColorComponent(QtColorLine::Red); m_ui.saturationColorLine->setColorComponent(QtColorLine::Green); m_ui.valueColorLine->setColorComponent(QtColorLine::Blue); setColorSpinBoxes(m_ui.colorButton->color());}void QtGradientStopsEditorPrivate::setColorSpinBoxes(const QColor &color){ m_ui.hueSpinBox->blockSignals(true); m_ui.saturationSpinBox->blockSignals(true); m_ui.valueSpinBox->blockSignals(true); m_ui.alphaSpinBox->blockSignals(true); if (m_ui.hsvRadioButton->isChecked()) { if (m_ui.hueSpinBox->maximum() != 359) m_ui.hueSpinBox->setMaximum(359); if (m_ui.hueSpinBox->value() != color.hue()) m_ui.hueSpinBox->setValue(color.hue()); if (m_ui.saturationSpinBox->value() != color.saturation()) m_ui.saturationSpinBox->setValue(color.saturation()); if (m_ui.valueSpinBox->value() != color.value()) m_ui.valueSpinBox->setValue(color.value()); } else { if (m_ui.hueSpinBox->maximum() != 255) m_ui.hueSpinBox->setMaximum(255); if (m_ui.hueSpinBox->value() != color.red()) m_ui.hueSpinBox->setValue(color.red()); if (m_ui.saturationSpinBox->value() != color.green()) m_ui.saturationSpinBox->setValue(color.green()); if (m_ui.valueSpinBox->value() != color.blue()) m_ui.valueSpinBox->setValue(color.blue()); } m_ui.alphaSpinBox->setValue(color.alpha()); m_ui.hueSpinBox->blockSignals(false); m_ui.saturationSpinBox->blockSignals(false); m_ui.valueSpinBox->blockSignals(false); m_ui.alphaSpinBox->blockSignals(false);}void QtGradientStopsEditorPrivate::slotCurrentStopChanged(QtGradientStop *stop){ if (!stop) { enableCurrent(false); return; } enableCurrent(true); QTimer::singleShot(0, q_ptr, SLOT(slotUpdatePositionSpinBox())); m_ui.colorButton->setColor(stop->color()); m_ui.hueColorLine->setColor(stop->color()); m_ui.saturationColorLine->setColor(stop->color()); m_ui.valueColorLine->setColor(stop->color()); m_ui.alphaColorLine->setColor(stop->color()); setColorSpinBoxes(stop->color());}void QtGradientStopsEditorPrivate::slotStopMoved(QtGradientStop *stop, qreal newPos){ QTimer::singleShot(0, q_ptr, SLOT(slotUpdatePositionSpinBox())); QMap<qreal, QColor> stops = stopsData(m_model->stops()); stops.remove(stop->position()); stops[newPos] = stop->color(); QGradientStops gradStops = makeGradientStops(stops); emit q_ptr->gradientStopsChanged(gradStops);}void QtGradientStopsEditorPrivate::slotStopAdded(QtGradientStop *stop){ QMap<qreal, QColor> stops = stopsData(m_model->stops()); stops[stop->position()] = stop->color(); QGradientStops gradStops = makeGradientStops(stops); emit q_ptr->gradientStopsChanged(gradStops);}void QtGradientStopsEditorPrivate::slotStopRemoved(QtGradientStop *stop){ QMap<qreal, QColor> stops = stopsData(m_model->stops()); stops.remove(stop->position()); QGradientStops gradStops = makeGradientStops(stops); emit q_ptr->gradientStopsChanged(gradStops);}void QtGradientStopsEditorPrivate::slotStopChanged(QtGradientStop *stop, const QColor &newColor){ if (m_model->currentStop() == stop) { m_ui.colorButton->setColor(newColor); m_ui.hueColorLine->setColor(newColor); m_ui.saturationColorLine->setColor(newColor); m_ui.valueColorLine->setColor(newColor); m_ui.alphaColorLine->setColor(newColor); setColorSpinBoxes(newColor); } QMap<qreal, QColor> stops = stopsData(m_model->stops()); stops[stop->position()] = newColor; QGradientStops gradStops = makeGradientStops(stops); emit q_ptr->gradientStopsChanged(gradStops);}void QtGradientStopsEditorPrivate::slotStopSelected(QtGradientStop *stop, bool selected){ Q_UNUSED(stop) Q_UNUSED(selected) QTimer::singleShot(0, q_ptr, SLOT(slotUpdatePositionSpinBox()));}void QtGradientStopsEditorPrivate::slotUpdatePositionSpinBox(){ QtGradientStop *current = m_model->currentStop(); if (!current) return; double min = 0.0; double max = 1.0; double pos = current->position(); QtGradientStop *first = m_model->firstSelected(); QtGradientStop *last = m_model->lastSelected(); if (first && last) { double minPos = pos - first->position() - 0.0004999; double maxPos = pos + 1.0 - last->position() + 0.0004999; if (max > maxPos) max = maxPos; if (min < minPos) min = minPos; if (first->position() == 0.0) min = pos; if (last->position() == 1.0) max = pos; } int spinMin = qRound(m_ui.positionSpinBox->minimum() * 1000); int spinMax = qRound(m_ui.positionSpinBox->maximum() * 1000);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?