diff --git a/GUI/View/Tool/DesignerHelper.cpp b/GUI/View/Tool/DesignerHelper.cpp index 94116f7c5500c28642ed0733e66ec568c75cd6ad..854a5ccf7f493867e45a36b9aaad15de48c47863 100644 --- a/GUI/View/Tool/DesignerHelper.cpp +++ b/GUI/View/Tool/DesignerHelper.cpp @@ -14,245 +14,6 @@ #include "GUI/View/Tool/DesignerHelper.h" #include "GUI/View/Tool/StyleUtils.h" -#include <QPainter> -#include <cmath> -#include <iostream> - -namespace { - -double m_current_zoom_level = 1.0; -} - - -QGradient DesignerHelper::getLayerGradient(const QColor& color, const QRectF& rect) -{ - QColor c = color; - c.setAlpha(160); - QLinearGradient result(rect.topLeft(), rect.bottomRight()); -#if QT_VERSION >= QT_VERSION_CHECK(5, 13, 0) - result.setColorAt(0, c.darker(150)); - result.setColorAt(0.5, c.lighter(200)); - result.setColorAt(1, c.darker(150)); -#else - result.setColorAt(0, c.dark(150)); - result.setColorAt(0.5, c.light(200)); - result.setColorAt(1, c.dark(150)); -#endif - return result; -} - -QGradient DesignerHelper::getDecorationGradient(const QColor& color, const QRectF& rect) -{ - const QColor& c = color; - // c.setAlpha(200); - QLinearGradient result(rect.x() + rect.width() / 2, rect.y(), rect.x() + rect.width() / 2, - rect.y() + rect.height()); - result.setColorAt(0, c); - result.setColorAt(0.5, c.lighter(150)); - result.setColorAt(1, c); - return result; -} - -QPixmap DesignerHelper::getSceneBackground() -{ - const int size = 10; - QPixmap result(size, size); - result.fill(QColor(250, 250, 250)); - QPainter tilePainter(&result); - QColor color(220, 220, 220); - tilePainter.fillRect(0.0, 0.0, 2, 2, color); - tilePainter.end(); - - return result; -} - -QPixmap DesignerHelper::getPixmapLayer() -{ - QRect rect(0, 0, layerWidth(), layerHeight()); - QPixmap pixmap(rect.width() + 1, rect.height() + 1); - pixmap.fill(Qt::transparent); - QPainter painter(&pixmap); - painter.setPen(Qt::black); - painter.setBrush(getLayerGradient(Qt::green, rect)); - painter.drawRect(rect); - return pixmap; -} - -QPixmap DesignerHelper::getPixmapMultiLayer() -{ - auto rect = getDefaultMultiLayerRect(); - QPixmap pixmap(rect.width() + 1, rect.height() + 1); - pixmap.fill(Qt::transparent); - QPainter painter(&pixmap); - painter.setPen(Qt::black); - painter.setBrush(getLayerGradient(QColor(75, 157, 249), rect)); - painter.drawRect(rect); - painter.setPen(Qt::DashLine); - painter.drawLine(0, layerHeight() * 0.3, rect.width(), layerHeight() * 0.3); - painter.drawLine(0, layerHeight() * 0.6, rect.width(), layerHeight() * 0.6); - return pixmap; -} - -QPixmap DesignerHelper::getPixmapParticleLayout() -{ - auto rect = getParticleLayoutBoundingRect(); - QPixmap pixmap(rect.width() + 1, rect.height() + 1); - pixmap.fill(Qt::transparent); - QPainter painter(&pixmap); - painter.setPen(Qt::black); - painter.setBrush(getDecorationGradient(QColor(135, 206, 50), rect)); - painter.drawRoundedRect(rect, 3, 3); - return pixmap; -} - -QPixmap DesignerHelper::getPixmapInterference() -{ - auto rect = getInterferenceBoundingRect(); - QPixmap pixmap(rect.width() + 1, rect.height() + 1); - pixmap.fill(Qt::transparent); - QPainter painter(&pixmap); - painter.setPen(Qt::black); - painter.setBrush(getDecorationGradient(Qt::lightGray, rect)); - painter.drawRoundedRect(rect, 3, 3); - return pixmap; -} - -QPixmap DesignerHelper::getPixmapParticle() -{ - auto rect = getParticleBoundingRect(); - QPixmap pixmap(rect.width() + 1, rect.height() + 1); - pixmap.fill(Qt::transparent); - QPainter painter(&pixmap); - painter.setPen(Qt::black); - painter.setBrush(getDecorationGradient(getDefaultParticleColor(), rect)); - painter.drawRoundedRect(rect, 5, 5); - return pixmap; -} - -bool DesignerHelper::sort_layers(QGraphicsItem* left, QGraphicsItem* right) -{ - return left->y() < right->y(); -} - -// non-linear conversion of layer's thickness in nanometers to screen size to have reasonable -// graphics representation -int DesignerHelper::nanometerToScreen(double nanometer) -{ - const int ymin(layerHeight()); - const int ymax(500); - int result(ymin); - if (nanometer > 0) - result = qBound(ymin, ymin + (int)std::pow(nanometer, 0.9), ymax); - return result; -} - -QRectF DesignerHelper::getDefaultBoundingRect(const QString& name) -{ - if (name == "MultiLayer") - return getDefaultMultiLayerRect(); - if (name == "Layer") - return QRectF(0, 0, layerWidth(), layerHeight()); - if (name == "ParticleLayout") - return getParticleLayoutBoundingRect(); - if (name == "Rotation") - return getTransformationBoundingRect(); - if (name.startsWith("FormFactor") || name == "Particle" || name == "ParticleCoreShell") - return getParticleBoundingRect(); - if (name.startsWith("Interference")) - return getInterferenceBoundingRect(); - return QRectF(0, 0, 50, 50); -} - -QColor DesignerHelper::getDefaultColor(const QString& name) -{ - if (name == "MultiLayer") - // return QColor(Qt::blue); - return QColor(51, 116, 255); - if (name == "Layer") - // return QColor(Qt::green); - return QColor(26, 156, 9); - if (name == "ParticleLayout") - return QColor(135, 206, 50); - if (name.startsWith("FormFactor") || name == "Particle" || name == "ParticleCoreShell") - return QColor(210, 223, 237); - if (name.startsWith("Interference")) - return QColor(255, 236, 139); - if (name == "Transparant red") - return QColor(0xFF, 0, 0, 0x80); - if (name == "Transparant blue") - return QColor(0, 0, 0xFF, 0x80); - return QColor(Qt::lightGray); -} - -QPixmap DesignerHelper::getMimePixmap(const QString& name) -{ - QRectF default_rect = getDefaultBoundingRect(name); - QRectF mime_rect(0, 0, default_rect.width() * m_current_zoom_level, - default_rect.height() * m_current_zoom_level); - - QPixmap pixmap(mime_rect.width() + 1, mime_rect.height() + 1); - pixmap.fill(Qt::transparent); - QPainter painter(&pixmap); - painter.setPen(Qt::black); - painter.setBrush(getDecorationGradient(getDefaultColor(name), mime_rect)); - painter.drawRoundedRect(mime_rect, 1, 1); - return pixmap; -} - -int DesignerHelper::getHeaderFontSize() -{ - return GUI::Util::Style::SystemPointSize() * 1.5; -} - -int DesignerHelper::layerWidth() -{ - return GUI::Util::Style::SizeOfLetterM().width() * 18; -} - -int DesignerHelper::layerHeight() -{ - return GUI::Util::Style::SizeOfLetterM().height() * 2; -} - -QColor DesignerHelper::getDefaultLayerColor() -{ - return QColor(Qt::lightGray); -} - -QRectF DesignerHelper::getDefaultMultiLayerRect() -{ - return QRectF(0, 0, layerWidth() * 1.15, layerHeight()); -} - -QRectF DesignerHelper::getParticleLayoutBoundingRect() -{ - return QRectF(0, 0, layerHeight() * 3.5, layerHeight() * 4.5); -} - -QRectF DesignerHelper::getInterferenceBoundingRect() -{ - return QRectF(0, 0, layerHeight() * 4.5, layerHeight() * 4); -} - -QColor DesignerHelper::getDefaultParticleColor() -{ - return QColor(210, 223, 237); -} - -QRectF DesignerHelper::getParticleBoundingRect() -{ - return QRectF(0, 0, layerHeight() * 3.5, layerHeight() * 4); -} - -QColor DesignerHelper::getDefaultTransformationColor() -{ - return QColor(145, 50, 220); -} - -QRectF DesignerHelper::getTransformationBoundingRect() -{ - return QRectF(0, 0, layerHeight() * 4, layerHeight() * 2); -} int DesignerHelper::getSectionFontSize() { diff --git a/GUI/View/Tool/DesignerHelper.h b/GUI/View/Tool/DesignerHelper.h index cc0b8d6dae702d81b0659132bd71a3ce38bdc374..08d9e251f470b1bf12678db648ad7c3d581aeab9 100644 --- a/GUI/View/Tool/DesignerHelper.h +++ b/GUI/View/Tool/DesignerHelper.h @@ -15,58 +15,10 @@ #ifndef BORNAGAIN_GUI_VIEW_TOOL_DESIGNERHELPER_H #define BORNAGAIN_GUI_VIEW_TOOL_DESIGNERHELPER_H -#include <QColor> -#include <QGradient> -#include <QGraphicsItem> -#include <QRect> - //! collection of static methods with SampleDesigner geometry settings class DesignerHelper { public: - static int layerWidth(); - static int layerHeight(); - static QColor getDefaultLayerColor(); - - static QRectF getDefaultMultiLayerRect(); - - static QRectF getParticleLayoutBoundingRect(); - - static QRectF getInterferenceBoundingRect(); - - static QColor getDefaultParticleColor(); - static QRectF getParticleBoundingRect(); - - static QColor getDefaultTransformationColor(); - static QRectF getTransformationBoundingRect(); - - static QGradient getLayerGradient(const QColor& color, const QRectF& rect); - static QGradient getDecorationGradient(const QColor& color, const QRectF& rect); - - static QPixmap getSceneBackground(); - static QPixmap getPixmapLayer(); - static QPixmap getPixmapMultiLayer(); - static QPixmap getPixmapParticleLayout(); - static QPixmap getPixmapInterference(); - static QPixmap getPixmapParticle(); - - //! sort graphics item according they y-coordinate - static bool sort_layers(QGraphicsItem* left, QGraphicsItem* right); - - //! non-linear conversion of layer's thickness in nanometers to screen size - //! to have reasonable graphics representation of layer in the form of QRect - static int nanometerToScreen(double nanometer); - - //! returns default bounding rectangle for given IvView name - static QRectF getDefaultBoundingRect(const QString& name); - - //! returns default color for IView with given name - static QColor getDefaultColor(const QString& name); - - //! returns Mime pixmap for givew IView name - static QPixmap getMimePixmap(const QString& name); - //! returns system dependent font size - static int getHeaderFontSize(); static int getSectionFontSize(); static int getLabelFontSize(); static int getPortFontSize();