/
ArtemNech
/
simpleOpenGL
Обзор
Документация
Войти
/
ArtemNech
/
simpleOpenGL
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
devOpt
backend/CScaleBox.cpp
118 строк
3 KB
Artem Nechitaylenko
initial
16 май 2026, 12:48
16 май 2026, 12:48
0d3ac6c
Код
Авторство
О чём код?
// // Created by artem on 1/9/25. // #include "CScaleBox.h" #include "CGraphicPainter.h" #include <QFontMetrics> #include <QApplication> #include "CColorTheme.h" #include <QImage> #include <QPainter> CScaleBox::CScaleBox(CPainter *painter) { m_painter = painter; m_size = m_painter->size().toSizeF(); m_dsb = new QDoubleSpinBox(painter); connect(m_dsb, &QDoubleSpinBox::editingFinished, this, &CScaleBox::hide_dsb); m_dsb->setMinimum(0.2); m_dsb->setMaximum(1000.0f); //m_dsb->setVisible(false); m_dsb->hide(); update_position(); } CScaleBox::~CScaleBox() { delete m_dsb; } void CScaleBox::doubleClicked() { m_dsb->setValue(m_scale); m_dsb->move(m_position.toPoint()); m_dsb->selectAll(); //m_dsb->setVisible(true); m_dsb->show(); m_dsb->setFocus(); } void CScaleBox::resized(int w, int h) { m_ogl_size = {(double )w, (double)h }; update_position(); } void CScaleBox::set_value(const float &value) { m_scale = value * 100.0f; update_data(); } QRectF *CScaleBox::rect() { return &m_rect; } QImage *CScaleBox::image() { return &m_image; } void CScaleBox::update_position() { update_data(); } void CScaleBox::update_data() { m_scale = round(m_scale * 1000.0f) / 1000.0f; char buff[20]; sprintf(buff, "%.1f%%", m_scale); std::string str = buff; QFont font = QApplication::font(); QFontMetrics fm(font); m_size = fm.size(Qt::TextSingleLine, str.c_str()); m_size.setHeight(m_size.height() + 2); m_size.setWidth(m_size.width() + 2); m_rect = QRectF(m_ogl_size.width() - difference_ - m_size.width(), m_ogl_size.height() - m_size.height(), m_size.width(), m_size.height()); m_position = m_rect.topLeft(); CColorTheme color_theme; ngraph::NColor tmp = color_theme.base_colors()->background_color.darker(130); QColor bkg = QColor(tmp.red(), tmp.green(), tmp.blue(), tmp.alpha()); m_image = QImage(m_rect.size().toSize(), QImage::Format_ARGB32); m_image.fill(bkg); QPainter painter(&m_image); tmp = color_theme.base_colors()->grid_colors.highlight.lighter(200); painter.setPen({tmp.red(), tmp.green(), tmp.blue(), tmp.alpha()}); painter.drawRect(0.0,0.0,m_rect.width()-1, m_rect.height()-1); painter.drawText(1, m_rect.height() - 5, str.c_str()); painter.end(); } float CScaleBox::get_value() const { return m_scale / 100.0f; } void CScaleBox::hide_dsb() { m_scale = m_dsb->value(); m_dsb->hide(); update_data(); emit scale_changed_by_user(m_scale / 100.0f); }