├── .gitignore ├── AUTHORS ├── screenshots ├── qt-creator-minimap-dark.png └── qt-creator-minimap-light.png ├── minimaptr.h ├── Minimap.json.in ├── MinimapPlugin.json.in ├── minimap_global.h ├── README.md ├── CMakeLists.txt ├── minimap.h ├── minimapconstants.h ├── minimapsettings.h ├── minimap.cpp ├── minimapstyle.h ├── minimapsettings.cpp ├── .github └── workflows │ └── build_cmake.yml ├── COPYING └── minimapstyle.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | *.user 2 | 3 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | (C) 2017 emJay Software Consulting AB 2 | Mattias Johansson 3 | 4 | email: matjo75@gmail.com 5 | -------------------------------------------------------------------------------- /screenshots/qt-creator-minimap-dark.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cristianadam/qt-creator-minimap/HEAD/screenshots/qt-creator-minimap-dark.png -------------------------------------------------------------------------------- /screenshots/qt-creator-minimap-light.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cristianadam/qt-creator-minimap/HEAD/screenshots/qt-creator-minimap-light.png -------------------------------------------------------------------------------- /minimaptr.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace Minimap { 6 | 7 | struct Tr 8 | { 9 | Q_DECLARE_TR_FUNCTIONS(QtC::Minimap) 10 | }; 11 | 12 | } // namespace Minimap 13 | -------------------------------------------------------------------------------- /Minimap.json.in: -------------------------------------------------------------------------------- 1 | { 2 | \"Name\" : \"Minimap\", 3 | \"Version\" : \"$$QTCREATOR_VERSION\", 4 | \"CompatVersion\" : \"$$QTCREATOR_COMPAT_VERSION\", 5 | \"Vendor\" : \"emJay Software Consulting AB\", 6 | \"Copyright\" : \"(C) 2017 emJay SOftware Consulting AB\", 7 | \"License\" : \"GNU LGPL 2.1\", 8 | \"Category\" : \"Qt Creator\", 9 | \"Description\" : \"Minimap Scrollbar\", 10 | $$dependencyList 11 | } 12 | -------------------------------------------------------------------------------- /MinimapPlugin.json.in: -------------------------------------------------------------------------------- 1 | { 2 | "Id" : "minimap", 3 | "Name" : "Minimap", 4 | "Version" : "${IDE_VERSION}", 5 | "CompatVersion" : "${IDE_VERSION_COMPAT}", 6 | "Vendor" : "Cristian Adam", 7 | "VendorId" : "cristianadam", 8 | "Copyright" : "(C) 2017 emJay SOftware Consulting AB, Cristian Adam, ${IDE_COPYRIGHT}", 9 | "License" : "GNU LGPL 2.1", 10 | "Description" : "Minimap scrollbar for Qt Creator", 11 | "LongDescription" : ${LONG_DESCRIPTION}, 12 | "Url" : "https://github.com/cristianadam/qt-creator-minimap", 13 | "DocumentationUrl" : "", 14 | ${IDE_PLUGIN_DEPENDENCIES} 15 | } 16 | -------------------------------------------------------------------------------- /minimap_global.h: -------------------------------------------------------------------------------- 1 | /* 2 | Minimap QtCreator plugin. 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 2.1 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not see 16 | http://www.gnu.org/licenses/lgpl-2.1.html. 17 | 18 | Copyright (c) 2017, emJay Software Consulting AB, See AUTHORS for details. 19 | */ 20 | 21 | #pragma once 22 | 23 | #include 24 | 25 | #if defined(MINIMAP_LIBRARY) 26 | #define MINIMAPSHARED_EXPORT Q_DECL_EXPORT 27 | #else 28 | #define MINIMAPSHARED_EXPORT Q_DECL_IMPORT 29 | #endif 30 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Minimap Qt Creator plugin 2 | 3 | The minimap Qt Creator plugin lets the user use a "minimap" as scrollbar for text editors. 4 | 5 | # Screenshots 6 | 7 | ![qt-creator-minimap-light.png](https://raw.githubusercontent.com/cristianadam/qt-creator-minimap/refs/heads/master/screenshots/qt-creator-minimap-light.png) 8 | 9 | ![qt-creator-minimap-dark.png](https://raw.githubusercontent.com/cristianadam/qt-creator-minimap/refs/heads/master/screenshots/qt-creator-minimap-dark.png) 10 | 11 | 12 | The minimap is only visible if is enabled, and text wrapping is **disabled** and if the line count of the file is less than the *Line Count Threshold* setting. If these criterias are not met an ordinary scrollbar is shown. 13 | 14 | Larger textfiles tend to render a rather messy minimap. Therefore the setting *Line Count Threshold* exist for the user to customize when the minimap is to be shown or not. 15 | 16 | You can edit the settings under *Minimap* tab in the *Text Editor* category. There are three settings available: 17 | 18 | * Enabled 19 | 20 | Uncheck this box to completely disable the minimap srcollbar 21 | 22 | * Width 23 | 24 | The width in pixels of the scrollbar. 25 | 26 | * Line Count Threshold 27 | 28 | The threshold where minimap scrollbar 29 | 30 | * Scrollbar slider alpha value 31 | 32 | The alpha value of the scrollbar slider 33 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.20) 2 | 3 | project(MinimapPlugin) 4 | 5 | set(CMAKE_AUTOMOC ON) 6 | set(CMAKE_AUTORCC ON) 7 | set(CMAKE_AUTOUIC ON) 8 | set(CMAKE_CXX_STANDARD 20) 9 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 10 | set(CMAKE_CXX_EXTENSIONS OFF) 11 | 12 | find_package(QtCreator REQUIRED COMPONENTS Core TextEditor) 13 | find_package(Qt6 COMPONENTS Widgets REQUIRED) 14 | 15 | # Add a CMake option that enables building your plugin with tests. 16 | # You don't want your released plugin binaries to contain tests, 17 | # so make that default to 'NO'. 18 | # Enable tests by passing -DWITH_TESTS=ON to CMake. 19 | option(WITH_TESTS "Builds with tests" NO) 20 | 21 | if(WITH_TESTS) 22 | # Look for QtTest 23 | find_package(Qt6 REQUIRED COMPONENTS Test) 24 | 25 | # Tell CMake functions like add_qtc_plugin about the QtTest component. 26 | set(IMPLICIT_DEPENDS Qt::Test) 27 | 28 | # Enable ctest for auto tests. 29 | enable_testing() 30 | endif() 31 | 32 | add_qtc_plugin(MinimapPlugin 33 | LONG_DESCRIPTION_MD README.md 34 | PLUGIN_DEPENDS 35 | QtCreator::Core 36 | QtCreator::TextEditor 37 | DEPENDS 38 | Qt::Widgets 39 | QtCreator::ExtensionSystem 40 | QtCreator::Utils 41 | SOURCES 42 | minimap.cpp minimap.h 43 | minimap_global.h 44 | minimapconstants.h 45 | minimaptr.h 46 | minimapsettings.cpp minimapsettings.h 47 | minimapstyle.cpp minimapstyle.h 48 | README.md 49 | ) 50 | -------------------------------------------------------------------------------- /minimap.h: -------------------------------------------------------------------------------- 1 | /* 2 | Minimap QtCreator plugin. 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 2.1 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not see 16 | http://www.gnu.org/licenses/lgpl-2.1.html. 17 | 18 | Copyright (c) 2017, emJay Software Consulting AB, See AUTHORS for details. 19 | */ 20 | 21 | #pragma once 22 | 23 | #include 24 | 25 | class QStyle; 26 | 27 | namespace Core { 28 | class IEditor; 29 | } 30 | 31 | namespace Utils { 32 | class FilePath; 33 | } 34 | 35 | namespace Minimap { 36 | namespace Internal { 37 | 38 | class MinimapPlugin : public ExtensionSystem::IPlugin 39 | { 40 | Q_OBJECT 41 | Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "MinimapPlugin.json") 42 | 43 | public: 44 | MinimapPlugin(); 45 | ~MinimapPlugin(); 46 | 47 | void initialize(); 48 | void setupQStyle(); 49 | 50 | private: 51 | void editorCreated(Core::IEditor *editor, const Utils::FilePath &fileName); 52 | }; 53 | } // namespace Internal 54 | } // namespace Minimap 55 | -------------------------------------------------------------------------------- /minimapconstants.h: -------------------------------------------------------------------------------- 1 | /* 2 | Minimap QtCreator plugin. 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 2.1 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not see 16 | http://www.gnu.org/licenses/lgpl-2.1.html. 17 | 18 | Copyright (c) 2017, emJay Software Consulting AB, See AUTHORS for details. 19 | */ 20 | 21 | //! @file minimapconstants.h 22 | //! 23 | //! Constans used throughout the Minimap plugin 24 | 25 | #pragma once 26 | 27 | namespace Minimap { 28 | namespace Constants { 29 | const char MINIMAP_ID[] = "Minimap.Minimap"; 30 | const char MINIMAP_SETTINGS[] = "Z.MinimapSettings"; 31 | const char MINIMAP_STYLE_OBJECT_PROPERTY[] = "Minimap.StyleObject"; 32 | const int MINIMAP_WIDTH_DEFAULT = 80; 33 | const int MINIMAP_EXTRA_AREA_WIDTH = 7; 34 | const int MINIMAP_MAX_LINE_COUNT_DEFAULT = 8000; 35 | const int MINIMAP_ALPHA_DEFAULT = 32; 36 | const bool MINIMAP_CENTER_ON_CLICK_DEFAULT = true; 37 | const bool MINIMAP_SHOW_LINE_TOOLTIP_DEFAULT = true; 38 | const int MINIMAP_PIXELS_PER_LINE_DEFAULT = 2; 39 | } // namespace Constants 40 | } // namespace Minimap 41 | -------------------------------------------------------------------------------- /minimapsettings.h: -------------------------------------------------------------------------------- 1 | /* 2 | Minimap QtCreator plugin. 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 2.1 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not see 16 | http://www.gnu.org/licenses/lgpl-2.1.html. 17 | 18 | Copyright (c) 2017, emJay Software Consulting AB, See AUTHORS for details. 19 | */ 20 | 21 | #pragma once 22 | 23 | #include 24 | 25 | #include 26 | 27 | namespace Minimap { 28 | namespace Internal { 29 | class MinimapSettingsPage; 30 | 31 | class MinimapSettings : public QObject 32 | { 33 | Q_OBJECT 34 | public: 35 | explicit MinimapSettings(QObject *parent); 36 | ~MinimapSettings(); 37 | 38 | Utils::Store toMap() const; 39 | void fromMap(const Utils::Store &map); 40 | 41 | static MinimapSettings *instance(); 42 | 43 | static bool enabled(); 44 | static int width(); 45 | static int lineCountThreshold(); 46 | static int alpha(); 47 | static bool centerOnClick(); 48 | static bool showLineTooltip(); 49 | static int pixelsPerLine(); 50 | 51 | signals: 52 | void enabledChanged(bool); 53 | void widthChanged(int); 54 | void lineCountThresholdChanged(int); 55 | void alphaChanged(int); 56 | void centerOnClickChanged(bool); 57 | void showLineTooltipChanged(bool); 58 | void pixelsPerLineChanged(int); 59 | 60 | private: 61 | friend class MinimapSettingsPageWidget; 62 | 63 | void setEnabled(bool enabled); 64 | void setWidth(int width); 65 | void setLineCountThreshold(int lineCountThreshold); 66 | void setAlpha(int alpha); 67 | void setCenterOnClick(bool centerOnClick); 68 | void setShowLineTooltip(bool showLineTooltip); 69 | void setPixelsPerLine(int pixelsPerLine); 70 | 71 | bool m_enabled; 72 | int m_width; 73 | int m_lineCountThreshold; 74 | int m_alpha; 75 | bool m_centerOnClick; 76 | bool m_showLineTooltip; 77 | int m_pixelsPerLine; 78 | MinimapSettingsPage *m_settingsPage; 79 | }; 80 | } // namespace Internal 81 | } // namespace Minimap 82 | -------------------------------------------------------------------------------- /minimap.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Minimap QtCreator plugin. 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 2.1 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not see 16 | http://www.gnu.org/licenses/lgpl-2.1.html. 17 | 18 | Copyright (c) 2017, emJay Software Consulting AB, See AUTHORS for details. 19 | */ 20 | 21 | #include "minimap.h" 22 | #include "minimapsettings.h" 23 | #include "minimapstyle.h" 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | #include 30 | 31 | #include 32 | 33 | namespace Minimap { 34 | namespace Internal { 35 | 36 | MinimapPlugin::MinimapPlugin() {} 37 | 38 | MinimapPlugin::~MinimapPlugin() 39 | { 40 | MinimapStyle *style = qobject_cast(qApp->style()); 41 | if (style) { 42 | qApp->setStyle(style->baseStyle()); 43 | } 44 | } 45 | 46 | void MinimapPlugin::initialize() 47 | { 48 | new MinimapSettings(this); 49 | 50 | Core::EditorManager *em = Core::EditorManager::instance(); 51 | connect(em, &Core::EditorManager::editorCreated, this, &MinimapPlugin::editorCreated); 52 | } 53 | 54 | void MinimapPlugin::setupQStyle() 55 | { 56 | // lazy setup of the style 57 | MinimapStyle *style = qobject_cast(qApp->style()); 58 | if (!style) { 59 | qDebug() << "Creating the minimap style"; 60 | auto minimapStyle = new MinimapStyle(qApp->style()); 61 | qApp->setStyle(minimapStyle); 62 | 63 | if (auto theme = Utils::creatorTheme()) 64 | minimapStyle->setSplitterColor(theme->color(Utils::Theme::SplitterColor)); 65 | } 66 | } 67 | 68 | void MinimapPlugin::editorCreated(Core::IEditor *editor, const Utils::FilePath &fileName) 69 | { 70 | Q_UNUSED(fileName); 71 | 72 | setupQStyle(); 73 | if (auto baseEditor = qobject_cast(editor)) 74 | MinimapStyle::createMinimapStyleObject(baseEditor); 75 | } 76 | } // namespace Internal 77 | } // namespace Minimap 78 | -------------------------------------------------------------------------------- /minimapstyle.h: -------------------------------------------------------------------------------- 1 | /* 2 | Minimap QtCreator plugin. 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 2.1 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not see 16 | http://www.gnu.org/licenses/lgpl-2.1.html. 17 | 18 | Copyright (c) 2017, emJay Software Consulting AB, See AUTHORS for details. 19 | */ 20 | 21 | #pragma once 22 | 23 | #include 24 | 25 | namespace TextEditor { 26 | class BaseTextEditor; 27 | } 28 | 29 | namespace Minimap { 30 | namespace Internal { 31 | class MinimapStyleObject; 32 | 33 | class MinimapStyle : public QProxyStyle 34 | { 35 | Q_OBJECT 36 | public: 37 | MinimapStyle(QStyle *style); 38 | 39 | void drawComplexControl(ComplexControl control, 40 | const QStyleOptionComplex *option, 41 | QPainter *painter, 42 | const QWidget *widget = Q_NULLPTR) const override; 43 | 44 | // need this due to QTBUG-24279 45 | SubControl hitTestComplexControl(ComplexControl control, 46 | const QStyleOptionComplex *option, 47 | const QPoint &pos, 48 | const QWidget *widget = Q_NULLPTR) const override; 49 | 50 | int pixelMetric(PixelMetric metric, 51 | const QStyleOption *option = Q_NULLPTR, 52 | const QWidget *widget = Q_NULLPTR) const override; 53 | 54 | QRect subControlRect(ComplexControl cc, 55 | const QStyleOptionComplex *opt, 56 | SubControl sc, 57 | const QWidget *widget) const override; 58 | 59 | static QObject *createMinimapStyleObject(TextEditor::BaseTextEditor *editor); 60 | 61 | QColor splitterColor() const; 62 | void setSplitterColor(const QColor &newSplitterColor); 63 | 64 | private: 65 | bool drawMinimap(const QStyleOptionComplex *, 66 | QPainter *, 67 | const QWidget *, 68 | MinimapStyleObject *) const; 69 | 70 | QColor m_splitterColor; 71 | }; 72 | } // namespace Internal 73 | } // namespace Minimap 74 | -------------------------------------------------------------------------------- /minimapsettings.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Minimap QtCreator plugin. 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 2.1 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not see 16 | http://www.gnu.org/licenses/lgpl-2.1.html. 17 | 18 | Copyright (c) 2017, emJay Software Consulting AB, See AUTHORS for details. 19 | */ 20 | 21 | #include "minimapsettings.h" 22 | #include "minimapconstants.h" 23 | #include "minimaptr.h" 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | #include 42 | 43 | namespace Minimap { 44 | namespace Internal { 45 | namespace { 46 | const char minimapPostFix[] = "Minimap"; 47 | const char enabledKey[] = "Enabled"; 48 | const char widthKey[] = "Width"; 49 | const char lineCountThresholdKey[] = "LineCountThresHold"; 50 | const char alphaKey[] = "Alpha"; 51 | const char centerOnClickKey[] = "CenterOnClick"; 52 | const char showLineTooltipKey[] = "ShowLineTooltip"; 53 | const char pixelsPerLineKey[] = "PixelsPerLine"; 54 | 55 | MinimapSettings *m_instance = 0; 56 | } // namespace 57 | 58 | class MinimapSettingsPageWidget : public Core::IOptionsPageWidget 59 | { 60 | public: 61 | MinimapSettingsPageWidget() 62 | { 63 | connect(TextEditor::TextEditorSettings::instance(), 64 | &TextEditor::TextEditorSettings::displaySettingsChanged, 65 | this, 66 | &MinimapSettingsPageWidget::displaySettingsChanged); 67 | m_textWrapping = TextEditor::TextEditorSettings::displaySettings().m_textWrapping; 68 | 69 | QVBoxLayout *layout = new QVBoxLayout; 70 | QGroupBox *groupBox = new QGroupBox(this); 71 | groupBox->setTitle(Tr::tr("Minimap")); 72 | layout->addWidget(groupBox); 73 | QFormLayout *form = new QFormLayout; 74 | m_enabled = new QCheckBox(groupBox); 75 | m_enabled->setToolTip(Tr::tr("Check to enable Minimap scrollbar")); 76 | m_enabled->setChecked(m_instance->m_enabled); 77 | form->addRow(Tr::tr("Enabled:"), m_enabled); 78 | m_width = new QSpinBox; 79 | m_width->setMinimum(1); 80 | m_width->setMaximum(std::numeric_limits::max()); 81 | m_width->setToolTip(Tr::tr("The width of the Minimap")); 82 | m_width->setValue(m_instance->m_width); 83 | form->addRow(Tr::tr("Width:"), m_width); 84 | m_lineCountThresHold = new QSpinBox; 85 | m_lineCountThresHold->setMinimum(1); 86 | m_lineCountThresHold->setMaximum(std::numeric_limits::max()); 87 | m_lineCountThresHold->setToolTip( 88 | Tr::tr("Line count threshold where no Minimap scrollbar is to be used")); 89 | m_lineCountThresHold->setValue(m_instance->m_lineCountThreshold); 90 | form->addRow(Tr::tr("Line Count Threshold:"), m_lineCountThresHold); 91 | m_alpha = new QSpinBox; 92 | m_alpha->setMinimum(0); 93 | m_alpha->setMaximum(255); 94 | m_alpha->setToolTip(Tr::tr("The alpha value of the scrollbar slider")); 95 | m_alpha->setValue(m_instance->m_alpha); 96 | form->addRow(Tr::tr("Scrollbar slider alpha value:"), m_alpha); 97 | m_centerOnClick = new QCheckBox(groupBox); 98 | m_centerOnClick->setToolTip( 99 | Tr::tr("Center viewport on mouse position when clicking and dragging")); 100 | m_centerOnClick->setChecked(m_instance->m_centerOnClick); 101 | form->addRow(Tr::tr("Center on click:"), m_centerOnClick); 102 | m_showLineTooltip = new QCheckBox(groupBox); 103 | m_showLineTooltip->setToolTip( 104 | Tr::tr("Show line range tooltip when interacting with minimap")); 105 | m_showLineTooltip->setChecked(m_instance->m_showLineTooltip); 106 | form->addRow(Tr::tr("Show line tooltip:"), m_showLineTooltip); 107 | m_pixelsPerLine = new QSpinBox; 108 | m_pixelsPerLine->setMinimum(1); 109 | m_pixelsPerLine->setMaximum(std::numeric_limits::max()); 110 | m_pixelsPerLine->setToolTip(Tr::tr("Pixels per line")); 111 | m_pixelsPerLine->setValue(m_instance->m_pixelsPerLine); 112 | form->addRow(Tr::tr("Pixels per line:"), m_pixelsPerLine); 113 | 114 | groupBox->setLayout(form); 115 | setLayout(layout); 116 | setEnabled(!m_textWrapping); 117 | setToolTip(m_textWrapping ? Tr::tr("Disable text wrapping to enable Minimap scrollbar") 118 | : QString()); 119 | } 120 | 121 | void apply() 122 | { 123 | bool save(false); 124 | if (m_enabled->isChecked() != MinimapSettings::enabled()) { 125 | m_instance->setEnabled(m_enabled->isChecked()); 126 | save = true; 127 | } 128 | if (m_width->value() != MinimapSettings::width()) { 129 | m_instance->setWidth(m_width->value()); 130 | save = true; 131 | } 132 | if (m_lineCountThresHold->value() != MinimapSettings::lineCountThreshold()) { 133 | m_instance->setLineCountThreshold(m_lineCountThresHold->value()); 134 | save = true; 135 | } 136 | if (m_alpha->value() != MinimapSettings::alpha()) { 137 | m_instance->setAlpha(m_alpha->value()); 138 | save = true; 139 | } 140 | if (m_centerOnClick->isChecked() != MinimapSettings::centerOnClick()) { 141 | m_instance->setCenterOnClick(m_centerOnClick->isChecked()); 142 | save = true; 143 | } 144 | if (m_showLineTooltip->isChecked() != MinimapSettings::showLineTooltip()) { 145 | m_instance->setShowLineTooltip(m_showLineTooltip->isChecked()); 146 | save = true; 147 | } 148 | if (m_pixelsPerLine->value() != MinimapSettings::pixelsPerLine()) { 149 | m_instance->setPixelsPerLine(m_pixelsPerLine->value()); 150 | save = true; 151 | } 152 | if (save) { 153 | Utils::storeToSettings(Utils::keyFromString(minimapPostFix), 154 | Core::ICore::settings(), 155 | m_instance->toMap()); 156 | } 157 | } 158 | 159 | private: 160 | void displaySettingsChanged(const TextEditor::DisplaySettings &settings) 161 | { 162 | m_textWrapping = settings.m_textWrapping; 163 | setEnabled(!m_textWrapping); 164 | setToolTip(m_textWrapping ? Tr::tr("Disable text wrapping to enable Minimap scrollbar") 165 | : QString()); 166 | } 167 | 168 | QCheckBox *m_enabled; 169 | QSpinBox *m_width; 170 | QSpinBox *m_lineCountThresHold; 171 | QSpinBox *m_alpha; 172 | QCheckBox *m_centerOnClick; 173 | QCheckBox *m_showLineTooltip; 174 | QSpinBox *m_pixelsPerLine; 175 | bool m_textWrapping; 176 | }; 177 | 178 | class MinimapSettingsPage : public Core::IOptionsPage 179 | { 180 | public: 181 | MinimapSettingsPage() 182 | { 183 | setId(Constants::MINIMAP_SETTINGS); 184 | setDisplayName(Tr::tr("Minimap")); 185 | setCategory(TextEditor::Constants::TEXT_EDITOR_SETTINGS_CATEGORY); 186 | setWidgetCreator([] { return new MinimapSettingsPageWidget; }); 187 | } 188 | }; 189 | 190 | MinimapSettings::MinimapSettings(QObject *parent) 191 | : QObject(parent) 192 | , m_enabled(true) 193 | , m_width(Constants::MINIMAP_WIDTH_DEFAULT) 194 | , m_lineCountThreshold(Constants::MINIMAP_MAX_LINE_COUNT_DEFAULT) 195 | , m_alpha(Constants::MINIMAP_ALPHA_DEFAULT) 196 | , m_centerOnClick(Constants::MINIMAP_CENTER_ON_CLICK_DEFAULT) 197 | , m_showLineTooltip(Constants::MINIMAP_SHOW_LINE_TOOLTIP_DEFAULT) 198 | , m_pixelsPerLine(Constants::MINIMAP_PIXELS_PER_LINE_DEFAULT) 199 | { 200 | QTC_ASSERT(!m_instance, return); 201 | m_instance = this; 202 | fromMap(Utils::storeFromSettings(Utils::keyFromString(minimapPostFix), Core::ICore::settings())); 203 | m_settingsPage = new MinimapSettingsPage(); 204 | } 205 | 206 | MinimapSettings::~MinimapSettings() 207 | { 208 | m_instance = 0; 209 | } 210 | 211 | MinimapSettings *MinimapSettings::instance() 212 | { 213 | return m_instance; 214 | } 215 | 216 | Utils::Store MinimapSettings::toMap() const 217 | { 218 | Utils::Store map; 219 | map.insert(enabledKey, m_enabled); 220 | map.insert(widthKey, m_width); 221 | map.insert(lineCountThresholdKey, m_lineCountThreshold); 222 | map.insert(alphaKey, m_alpha); 223 | map.insert(centerOnClickKey, m_centerOnClick); 224 | map.insert(showLineTooltipKey, m_showLineTooltip); 225 | map.insert(pixelsPerLineKey, m_pixelsPerLine); 226 | return map; 227 | } 228 | 229 | void MinimapSettings::fromMap(const Utils::Store &map) 230 | { 231 | m_enabled = map.value(enabledKey, m_enabled).toBool(); 232 | m_width = map.value(widthKey, m_width).toInt(); 233 | m_lineCountThreshold = map.value(lineCountThresholdKey, m_lineCountThreshold).toInt(); 234 | m_alpha = map.value(alphaKey, m_alpha).toInt(); 235 | m_centerOnClick = map.value(centerOnClickKey, m_centerOnClick).toBool(); 236 | m_showLineTooltip = map.value(showLineTooltipKey, m_showLineTooltip).toBool(); 237 | m_pixelsPerLine = map.value(pixelsPerLineKey, m_pixelsPerLine).toInt(); 238 | } 239 | 240 | bool MinimapSettings::enabled() 241 | { 242 | return m_instance->m_enabled; 243 | } 244 | 245 | int MinimapSettings::width() 246 | { 247 | return m_instance->m_width; 248 | } 249 | 250 | int MinimapSettings::lineCountThreshold() 251 | { 252 | return m_instance->m_lineCountThreshold; 253 | } 254 | 255 | int MinimapSettings::alpha() 256 | { 257 | return m_instance->m_alpha; 258 | } 259 | 260 | bool MinimapSettings::centerOnClick() 261 | { 262 | return m_instance->m_centerOnClick; 263 | } 264 | 265 | bool MinimapSettings::showLineTooltip() 266 | { 267 | return m_instance->m_showLineTooltip; 268 | } 269 | 270 | int MinimapSettings::pixelsPerLine() 271 | { 272 | return m_instance->m_pixelsPerLine; 273 | } 274 | 275 | void MinimapSettings::setEnabled(bool enabled) 276 | { 277 | if (m_enabled != enabled) { 278 | m_enabled = enabled; 279 | emit enabledChanged(enabled); 280 | } 281 | } 282 | 283 | void MinimapSettings::setWidth(int width) 284 | { 285 | if (m_width != width) { 286 | m_width = width; 287 | emit widthChanged(width); 288 | } 289 | } 290 | 291 | void MinimapSettings::setLineCountThreshold(int lineCountThreshold) 292 | { 293 | if (m_lineCountThreshold != lineCountThreshold) { 294 | m_lineCountThreshold = lineCountThreshold; 295 | emit lineCountThresholdChanged(lineCountThreshold); 296 | } 297 | } 298 | 299 | void MinimapSettings::setAlpha(int alpha) 300 | { 301 | if (m_alpha != alpha) { 302 | m_alpha = alpha; 303 | emit alphaChanged(alpha); 304 | } 305 | } 306 | 307 | void MinimapSettings::setCenterOnClick(bool centerOnClick) 308 | { 309 | if (m_centerOnClick != centerOnClick) { 310 | m_centerOnClick = centerOnClick; 311 | emit centerOnClickChanged(centerOnClick); 312 | } 313 | } 314 | 315 | void MinimapSettings::setShowLineTooltip(bool showLineTooltip) 316 | { 317 | if (m_showLineTooltip != showLineTooltip) { 318 | m_showLineTooltip = showLineTooltip; 319 | emit showLineTooltipChanged(showLineTooltip); 320 | } 321 | } 322 | 323 | void MinimapSettings::setPixelsPerLine(int pixelsPerLine) 324 | { 325 | if (m_pixelsPerLine != pixelsPerLine) { 326 | m_pixelsPerLine = pixelsPerLine; 327 | emit pixelsPerLineChanged(pixelsPerLine); 328 | } 329 | } 330 | } // namespace Internal 331 | } // namespace Minimap 332 | -------------------------------------------------------------------------------- /.github/workflows/build_cmake.yml: -------------------------------------------------------------------------------- 1 | name: Build plugin 2 | 3 | on: [push] 4 | 5 | env: 6 | PLUGIN_NAME: MinimapPlugin 7 | QT_VERSION: 6.10.0 8 | QT_CREATOR_VERSION: 18.0.0 9 | MACOS_DEPLOYMENT_TARGET: "11.0" 10 | CMAKE_VERSION: "3.29.6" 11 | NINJA_VERSION: "1.12.1" 12 | 13 | jobs: 14 | build: 15 | name: ${{ matrix.config.name }} 16 | runs-on: ${{ matrix.config.os }} 17 | outputs: 18 | tag: ${{ steps.git.outputs.tag }} 19 | strategy: 20 | matrix: 21 | config: 22 | - { 23 | name: "Windows Latest MSVC", artifact: "Windows-x64", 24 | os: windows-latest, 25 | platform: windows_x64, 26 | cc: "cl", cxx: "cl", 27 | environment_script: "C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Auxiliary/Build/vcvars64.bat", 28 | } 29 | - { 30 | name: "Windows Latest MSVC Arm64", artifact: "Windows-arm64", 31 | os: windows-11-arm, 32 | platform: windows_arm64, 33 | cc: "cl", cxx: "cl", 34 | environment_script: "C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Auxiliary/Build/vcvarsarm64.bat", 35 | } 36 | - { 37 | name: "Ubuntu Latest GCC", artifact: "Linux-x64", 38 | os: ubuntu-latest, 39 | platform: linux_x64, 40 | cc: "gcc", cxx: "g++" 41 | } 42 | - { 43 | name: "Ubuntu Latest GCC Arm64", artifact: "Linux-arm64", 44 | os: ubuntu-24.04-arm, 45 | platform: linux_arm64, 46 | cc: "gcc", cxx: "g++" 47 | } 48 | - { 49 | name: "macOS Latest Clang", artifact: "macOS-universal", 50 | os: macos-latest, 51 | platform: mac_x64, 52 | cc: "clang", cxx: "clang++" 53 | } 54 | 55 | steps: 56 | - uses: actions/checkout@v4 57 | - name: Checkout submodules 58 | id: git 59 | shell: cmake -P {0} 60 | run: | 61 | if (${{github.ref}} MATCHES "tags/v(.*)") 62 | file(APPEND "$ENV{GITHUB_OUTPUT}" "tag=${CMAKE_MATCH_1}") 63 | else() 64 | file(APPEND "$ENV{GITHUB_OUTPUT}" "tag=${{github.run_id}}") 65 | endif() 66 | 67 | - name: Download Ninja and CMake 68 | uses: lukka/get-cmake@latest 69 | with: 70 | cmakeVersion: ${{ env.CMAKE_VERSION }} 71 | ninjaVersion: ${{ env.NINJA_VERSION }} 72 | 73 | - name: Install system libs 74 | shell: cmake -P {0} 75 | run: | 76 | if ("${{ matrix.config.platform }}" MATCHES "linux") 77 | execute_process( 78 | COMMAND sudo apt-get update 79 | ) 80 | execute_process( 81 | COMMAND sudo apt-get install -y libgl1-mesa-dev 82 | RESULT_VARIABLE result 83 | ) 84 | if (NOT result EQUAL 0) 85 | message(FATAL_ERROR "Failed to install dependencies") 86 | endif() 87 | endif() 88 | 89 | - name: Download Qt 90 | id: qt 91 | shell: cmake -P {0} 92 | run: | 93 | set(qt_version "$ENV{QT_VERSION}") 94 | 95 | function(download_qt platform export_qt_dir) 96 | string(REPLACE "." "" qt_version_dotless "${qt_version}") 97 | if (platform STREQUAL "windows_x64") 98 | set(url_os "windows_x86") 99 | set(qt_package_arch_suffix "win64_msvc2022_64") 100 | set(qt_dir_prefix "${qt_version}/msvc_64") 101 | set(qt_package_suffix "-Windows-Windows_11_24H2-MSVC2022-Windows-Windows_11_24H2-X86_64") 102 | elseif (platform STREQUAL "windows_arm64") 103 | set(url_os "windows_arm64") 104 | set(qt_package_arch_suffix "win64_msvc2022_arm64") 105 | set(qt_dir_prefix "${qt_version}/msvc2022_arm64") 106 | set(qt_package_suffix "-Windows-Windows_11_23H2-MSVC2022-Windows-Windows_11_23H2-AARCH64") 107 | elseif (platform STREQUAL "linux_x64") 108 | set(url_os "linux_x64") 109 | set(qt_package_arch_suffix "linux_gcc_64") 110 | set(qt_dir_prefix "${qt_version}/gcc_64") 111 | set(qt_package_suffix "-Linux-RHEL_9_4-GCC-Linux-RHEL_9_4-X86_64") 112 | elseif (platform STREQUAL "linux_arm64") 113 | set(url_os "linux_arm64") 114 | set(qt_package_arch_suffix "linux_gcc_arm64") 115 | set(qt_dir_prefix "${qt_version}/gcc_arm64") 116 | set(qt_package_suffix "-Linux-Ubuntu_24_04-GCC-Linux-Ubuntu_24_04-AARCH64") 117 | elseif (platform STREQUAL "mac_x64") 118 | set(url_os "mac_x64") 119 | set(qt_package_arch_suffix "clang_64") 120 | set(qt_dir_prefix "${qt_version}/macos") 121 | set(qt_package_suffix "-MacOS-MacOS_15-Clang-MacOS-MacOS_15-X86_64-ARM64") 122 | endif() 123 | 124 | set(qt_base_url "https://download.qt.io/online/qtsdkrepository/${url_os}/desktop/qt6_${qt_version_dotless}/qt6_${qt_version_dotless}") 125 | file(DOWNLOAD "${qt_base_url}/Updates.xml" ./Updates.xml SHOW_PROGRESS) 126 | 127 | file(READ ./Updates.xml updates_xml) 128 | string(REGEX MATCH "qt.qt6.*([0-9+-.]+)" updates_xml_output "${updates_xml}") 129 | set(qt_package_version ${CMAKE_MATCH_1}) 130 | 131 | # Save the path for other steps 132 | file(TO_CMAKE_PATH "$ENV{GITHUB_WORKSPACE}/qt6/${qt_dir_prefix}" qt_dir) 133 | 134 | if (export_qt_dir) 135 | file(APPEND "$ENV{GITHUB_OUTPUT}" "qt_dir=${qt_dir}") 136 | endif() 137 | 138 | message("Downloading Qt to ${qt_dir}") 139 | function(downloadAndExtract url archive subdir) 140 | file(MAKE_DIRECTORY "${qt_dir}/${subdir}") 141 | message("Downloading ${url}") 142 | message("... extracting to ${qt_dir}/${subdir}") 143 | file(DOWNLOAD "${url}" "$ENV{GITHUB_WORKSPACE}/${archive}" SHOW_PROGRESS) 144 | execute_process(COMMAND ${CMAKE_COMMAND} -E tar xvf "$ENV{GITHUB_WORKSPACE}/${archive}" WORKING_DIRECTORY "${qt_dir}/${subdir}") 145 | endfunction() 146 | 147 | foreach(package qtbase qtdeclarative qttools) 148 | downloadAndExtract( 149 | "${qt_base_url}/qt.qt6.${qt_version_dotless}.${qt_package_arch_suffix}/${qt_package_version}${package}${qt_package_suffix}.7z" 150 | ${package}.7z 151 | "" 152 | ) 153 | endforeach() 154 | 155 | foreach(package qt5compat qtshadertools) 156 | downloadAndExtract( 157 | "${qt_base_url}/qt.qt6.${qt_version_dotless}.addons.${package}.${qt_package_arch_suffix}/${qt_package_version}${package}${qt_package_suffix}.7z" 158 | ${package}.7z 159 | "" 160 | ) 161 | endforeach() 162 | 163 | # uic depends on libicu*.so 164 | if (platform MATCHES "linux") 165 | if (platform STREQUAL "linux_x64") 166 | if (qt_version VERSION_LESS "6.7.0") 167 | set(uic_suffix "Rhel7.2-x64") 168 | else() 169 | set(uic_suffix "Rhel8.6-x86_64") 170 | endif() 171 | else() 172 | set(uic_suffix "Debian11.6-arm64") 173 | endif() 174 | downloadAndExtract( 175 | "${qt_base_url}/qt.qt6.${qt_version_dotless}.${qt_package_arch_suffix}/${qt_package_version}icu-linux-${uic_suffix}.7z" 176 | icu.7z 177 | "lib" 178 | ) 179 | endif() 180 | 181 | execute_process(COMMAND ${qt_dir}/bin/qmake -query) 182 | endfunction() 183 | 184 | if ("${{ matrix.config.platform }}" STREQUAL "windows_x64") 185 | download_qt(windows_x64 TRUE) 186 | elseif ("${{ matrix.config.platform }}" STREQUAL "windows_arm64") 187 | download_qt(windows_arm64 TRUE) 188 | elseif ("${{ matrix.config.platform }}" STREQUAL "linux_x64") 189 | download_qt(linux_x64 TRUE) 190 | elseif ("${{ matrix.config.platform }}" STREQUAL "linux_arm64") 191 | download_qt(linux_arm64 TRUE) 192 | elseif ("${{ runner.os }}" STREQUAL "macOS") 193 | download_qt(mac_x64 TRUE) 194 | endif() 195 | 196 | - name: Download Qt Creator 197 | uses: qt-creator/install-dev-package@v2.1 198 | with: 199 | version: ${{ env.QT_CREATOR_VERSION }} 200 | unzip-to: 'qtcreator' 201 | platform: ${{ matrix.config.platform }} 202 | 203 | - name: Extract Qt Creator 204 | id: qt_creator 205 | shell: cmake -P {0} 206 | run: | 207 | file(TO_CMAKE_PATH "$ENV{GITHUB_WORKSPACE}/qtcreator" qtc_dir) 208 | file(APPEND "$ENV{GITHUB_OUTPUT}" "qtc_dir=${qtc_dir}") 209 | 210 | - name: Build 211 | shell: cmake -P {0} 212 | run: | 213 | set(ENV{CC} ${{ matrix.config.cc }}) 214 | set(ENV{CXX} ${{ matrix.config.cxx }}) 215 | set(ENV{MACOSX_DEPLOYMENT_TARGET} "${{ env.MACOS_DEPLOYMENT_TARGET }}") 216 | 217 | if ("${{ runner.os }}" STREQUAL "Windows" AND NOT "x${{ matrix.config.environment_script }}" STREQUAL "x") 218 | execute_process( 219 | COMMAND "${{ matrix.config.environment_script }}" && set 220 | OUTPUT_FILE environment_script_output.txt 221 | ) 222 | file(STRINGS environment_script_output.txt output_lines) 223 | foreach(line IN LISTS output_lines) 224 | if (line MATCHES "^([a-zA-Z0-9_-]+)=(.*)$") 225 | set(ENV{${CMAKE_MATCH_1}} "${CMAKE_MATCH_2}") 226 | endif() 227 | endforeach() 228 | endif() 229 | 230 | set(ENV{NINJA_STATUS} "[%f/%t %o/sec] ") 231 | if ("${{ runner.os }}" STREQUAL "macOS") 232 | set(ENV{CMAKE_OSX_ARCHITECTURES} "x86_64;arm64") 233 | endif() 234 | 235 | set(build_plugin_py "scripts/build_plugin.py") 236 | foreach(dir "share/qtcreator/scripts" "Qt Creator.app/Contents/Resources/scripts" "Contents/Resources/scripts") 237 | if(EXISTS "${{ steps.qt_creator.outputs.qtc_dir }}/${dir}/build_plugin.py") 238 | set(build_plugin_py "${dir}/build_plugin.py") 239 | break() 240 | endif() 241 | endforeach() 242 | 243 | execute_process( 244 | COMMAND python 245 | -u 246 | "${{ steps.qt_creator.outputs.qtc_dir }}/${build_plugin_py}" 247 | --name "$ENV{PLUGIN_NAME}-$ENV{QT_CREATOR_VERSION}-${{ matrix.config.artifact }}" 248 | --src . 249 | --build build 250 | --qt-path "${{ steps.qt.outputs.qt_dir }}" 251 | --qtc-path "${{ steps.qt_creator.outputs.qtc_dir }}" 252 | --output-path "$ENV{GITHUB_WORKSPACE}" 253 | ${additional_config} 254 | RESULT_VARIABLE result 255 | ) 256 | if (NOT result EQUAL 0) 257 | string(REGEX MATCH "FAILED:.*$" error_message "${output}") 258 | string(REPLACE "\n" "%0A" error_message "${error_message}") 259 | message("::error::${error_message}") 260 | message(FATAL_ERROR "Build failed") 261 | endif() 262 | 263 | - name: Upload 264 | uses: actions/upload-artifact@v4 265 | with: 266 | path: ./${{ env.PLUGIN_NAME }}-${{ env.QT_CREATOR_VERSION }}-${{ matrix.config.artifact }}.7z 267 | name: ${{ env.PLUGIN_NAME}}-${{ env.QT_CREATOR_VERSION }}-${{ matrix.config.artifact }}.7z 268 | 269 | # The json is the same for all platforms, but we need to save one 270 | - name: Upload plugin json 271 | if: matrix.config.platform == 'linux_arm64' 272 | uses: actions/upload-artifact@v4 273 | with: 274 | name: ${{ env.PLUGIN_NAME }}.json 275 | path: ./build/build/${{ env.PLUGIN_NAME }}.json 276 | 277 | release: 278 | if: contains(github.ref, 'tags/v') 279 | runs-on: ubuntu-latest 280 | needs: [build] 281 | 282 | steps: 283 | - name: Download artifacts 284 | uses: actions/download-artifact@v4 285 | with: 286 | path: release-with-dirs 287 | 288 | - name: Fixup artifacts 289 | run: | 290 | mkdir release 291 | mv release-with-dirs/*/* release/ 292 | 293 | - name: Create Release 294 | id: create_release 295 | uses: softprops/action-gh-release@v2 296 | env: 297 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 298 | with: 299 | tag_name: v${{ needs.build.outputs.tag }} 300 | files: | 301 | release/${{ env.PLUGIN_NAME}}-${{ env.QT_CREATOR_VERSION }}-Linux-arm64.7z 302 | release/${{ env.PLUGIN_NAME}}-${{ env.QT_CREATOR_VERSION }}-Linux-x64.7z 303 | release/${{ env.PLUGIN_NAME}}-${{ env.QT_CREATOR_VERSION }}-macOS-universal.7z 304 | release/${{ env.PLUGIN_NAME}}-${{ env.QT_CREATOR_VERSION }}-Windows-arm64.7z 305 | release/${{ env.PLUGIN_NAME}}-${{ env.QT_CREATOR_VERSION }}-Windows-x64.7z 306 | draft: false 307 | prerelease: false 308 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 2.1, February 1999 3 | 4 | Copyright (C) 1991, 1999 Free Software Foundation, Inc. 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | [This is the first released version of the Lesser GPL. It also counts 10 | as the successor of the GNU Library Public License, version 2, hence 11 | the version number 2.1.] 12 | 13 | Preamble 14 | 15 | The licenses for most software are designed to take away your 16 | freedom to share and change it. By contrast, the GNU General Public 17 | Licenses are intended to guarantee your freedom to share and change 18 | free software--to make sure the software is free for all its users. 19 | 20 | This license, the Lesser General Public License, applies to some 21 | specially designated software packages--typically libraries--of the 22 | Free Software Foundation and other authors who decide to use it. You 23 | can use it too, but we suggest you first think carefully about whether 24 | this license or the ordinary General Public License is the better 25 | strategy to use in any particular case, based on the explanations below. 26 | 27 | When we speak of free software, we are referring to freedom of use, 28 | not price. Our General Public Licenses are designed to make sure that 29 | you have the freedom to distribute copies of free software (and charge 30 | for this service if you wish); that you receive source code or can get 31 | it if you want it; that you can change the software and use pieces of 32 | it in new free programs; and that you are informed that you can do 33 | these things. 34 | 35 | To protect your rights, we need to make restrictions that forbid 36 | distributors to deny you these rights or to ask you to surrender these 37 | rights. These restrictions translate to certain responsibilities for 38 | you if you distribute copies of the library or if you modify it. 39 | 40 | For example, if you distribute copies of the library, whether gratis 41 | or for a fee, you must give the recipients all the rights that we gave 42 | you. You must make sure that they, too, receive or can get the source 43 | code. If you link other code with the library, you must provide 44 | complete object files to the recipients, so that they can relink them 45 | with the library after making changes to the library and recompiling 46 | it. And you must show them these terms so they know their rights. 47 | 48 | We protect your rights with a two-step method: (1) we copyright the 49 | library, and (2) we offer you this license, which gives you legal 50 | permission to copy, distribute and/or modify the library. 51 | 52 | To protect each distributor, we want to make it very clear that 53 | there is no warranty for the free library. Also, if the library is 54 | modified by someone else and passed on, the recipients should know 55 | that what they have is not the original version, so that the original 56 | author's reputation will not be affected by problems that might be 57 | introduced by others. 58 | 59 | Finally, software patents pose a constant threat to the existence of 60 | any free program. We wish to make sure that a company cannot 61 | effectively restrict the users of a free program by obtaining a 62 | restrictive license from a patent holder. Therefore, we insist that 63 | any patent license obtained for a version of the library must be 64 | consistent with the full freedom of use specified in this license. 65 | 66 | Most GNU software, including some libraries, is covered by the 67 | ordinary GNU General Public License. This license, the GNU Lesser 68 | General Public License, applies to certain designated libraries, and 69 | is quite different from the ordinary General Public License. We use 70 | this license for certain libraries in order to permit linking those 71 | libraries into non-free programs. 72 | 73 | When a program is linked with a library, whether statically or using 74 | a shared library, the combination of the two is legally speaking a 75 | combined work, a derivative of the original library. The ordinary 76 | General Public License therefore permits such linking only if the 77 | entire combination fits its criteria of freedom. The Lesser General 78 | Public License permits more lax criteria for linking other code with 79 | the library. 80 | 81 | We call this license the "Lesser" General Public License because it 82 | does Less to protect the user's freedom than the ordinary General 83 | Public License. It also provides other free software developers Less 84 | of an advantage over competing non-free programs. These disadvantages 85 | are the reason we use the ordinary General Public License for many 86 | libraries. However, the Lesser license provides advantages in certain 87 | special circumstances. 88 | 89 | For example, on rare occasions, there may be a special need to 90 | encourage the widest possible use of a certain library, so that it becomes 91 | a de-facto standard. To achieve this, non-free programs must be 92 | allowed to use the library. A more frequent case is that a free 93 | library does the same job as widely used non-free libraries. In this 94 | case, there is little to gain by limiting the free library to free 95 | software only, so we use the Lesser General Public License. 96 | 97 | In other cases, permission to use a particular library in non-free 98 | programs enables a greater number of people to use a large body of 99 | free software. For example, permission to use the GNU C Library in 100 | non-free programs enables many more people to use the whole GNU 101 | operating system, as well as its variant, the GNU/Linux operating 102 | system. 103 | 104 | Although the Lesser General Public License is Less protective of the 105 | users' freedom, it does ensure that the user of a program that is 106 | linked with the Library has the freedom and the wherewithal to run 107 | that program using a modified version of the Library. 108 | 109 | The precise terms and conditions for copying, distribution and 110 | modification follow. Pay close attention to the difference between a 111 | "work based on the library" and a "work that uses the library". The 112 | former contains code derived from the library, whereas the latter must 113 | be combined with the library in order to run. 114 | 115 | GNU LESSER GENERAL PUBLIC LICENSE 116 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 117 | 118 | 0. This License Agreement applies to any software library or other 119 | program which contains a notice placed by the copyright holder or 120 | other authorized party saying it may be distributed under the terms of 121 | this Lesser General Public License (also called "this License"). 122 | Each licensee is addressed as "you". 123 | 124 | A "library" means a collection of software functions and/or data 125 | prepared so as to be conveniently linked with application programs 126 | (which use some of those functions and data) to form executables. 127 | 128 | The "Library", below, refers to any such software library or work 129 | which has been distributed under these terms. A "work based on the 130 | Library" means either the Library or any derivative work under 131 | copyright law: that is to say, a work containing the Library or a 132 | portion of it, either verbatim or with modifications and/or translated 133 | straightforwardly into another language. (Hereinafter, translation is 134 | included without limitation in the term "modification".) 135 | 136 | "Source code" for a work means the preferred form of the work for 137 | making modifications to it. For a library, complete source code means 138 | all the source code for all modules it contains, plus any associated 139 | interface definition files, plus the scripts used to control compilation 140 | and installation of the library. 141 | 142 | Activities other than copying, distribution and modification are not 143 | covered by this License; they are outside its scope. The act of 144 | running a program using the Library is not restricted, and output from 145 | such a program is covered only if its contents constitute a work based 146 | on the Library (independent of the use of the Library in a tool for 147 | writing it). Whether that is true depends on what the Library does 148 | and what the program that uses the Library does. 149 | 150 | 1. You may copy and distribute verbatim copies of the Library's 151 | complete source code as you receive it, in any medium, provided that 152 | you conspicuously and appropriately publish on each copy an 153 | appropriate copyright notice and disclaimer of warranty; keep intact 154 | all the notices that refer to this License and to the absence of any 155 | warranty; and distribute a copy of this License along with the 156 | Library. 157 | 158 | You may charge a fee for the physical act of transferring a copy, 159 | and you may at your option offer warranty protection in exchange for a 160 | fee. 161 | 162 | 2. You may modify your copy or copies of the Library or any portion 163 | of it, thus forming a work based on the Library, and copy and 164 | distribute such modifications or work under the terms of Section 1 165 | above, provided that you also meet all of these conditions: 166 | 167 | a) The modified work must itself be a software library. 168 | 169 | b) You must cause the files modified to carry prominent notices 170 | stating that you changed the files and the date of any change. 171 | 172 | c) You must cause the whole of the work to be licensed at no 173 | charge to all third parties under the terms of this License. 174 | 175 | d) If a facility in the modified Library refers to a function or a 176 | table of data to be supplied by an application program that uses 177 | the facility, other than as an argument passed when the facility 178 | is invoked, then you must make a good faith effort to ensure that, 179 | in the event an application does not supply such function or 180 | table, the facility still operates, and performs whatever part of 181 | its purpose remains meaningful. 182 | 183 | (For example, a function in a library to compute square roots has 184 | a purpose that is entirely well-defined independent of the 185 | application. Therefore, Subsection 2d requires that any 186 | application-supplied function or table used by this function must 187 | be optional: if the application does not supply it, the square 188 | root function must still compute square roots.) 189 | 190 | These requirements apply to the modified work as a whole. If 191 | identifiable sections of that work are not derived from the Library, 192 | and can be reasonably considered independent and separate works in 193 | themselves, then this License, and its terms, do not apply to those 194 | sections when you distribute them as separate works. But when you 195 | distribute the same sections as part of a whole which is a work based 196 | on the Library, the distribution of the whole must be on the terms of 197 | this License, whose permissions for other licensees extend to the 198 | entire whole, and thus to each and every part regardless of who wrote 199 | it. 200 | 201 | Thus, it is not the intent of this section to claim rights or contest 202 | your rights to work written entirely by you; rather, the intent is to 203 | exercise the right to control the distribution of derivative or 204 | collective works based on the Library. 205 | 206 | In addition, mere aggregation of another work not based on the Library 207 | with the Library (or with a work based on the Library) on a volume of 208 | a storage or distribution medium does not bring the other work under 209 | the scope of this License. 210 | 211 | 3. You may opt to apply the terms of the ordinary GNU General Public 212 | License instead of this License to a given copy of the Library. To do 213 | this, you must alter all the notices that refer to this License, so 214 | that they refer to the ordinary GNU General Public License, version 2, 215 | instead of to this License. (If a newer version than version 2 of the 216 | ordinary GNU General Public License has appeared, then you can specify 217 | that version instead if you wish.) Do not make any other change in 218 | these notices. 219 | 220 | Once this change is made in a given copy, it is irreversible for 221 | that copy, so the ordinary GNU General Public License applies to all 222 | subsequent copies and derivative works made from that copy. 223 | 224 | This option is useful when you wish to copy part of the code of 225 | the Library into a program that is not a library. 226 | 227 | 4. You may copy and distribute the Library (or a portion or 228 | derivative of it, under Section 2) in object code or executable form 229 | under the terms of Sections 1 and 2 above provided that you accompany 230 | it with the complete corresponding machine-readable source code, which 231 | must be distributed under the terms of Sections 1 and 2 above on a 232 | medium customarily used for software interchange. 233 | 234 | If distribution of object code is made by offering access to copy 235 | from a designated place, then offering equivalent access to copy the 236 | source code from the same place satisfies the requirement to 237 | distribute the source code, even though third parties are not 238 | compelled to copy the source along with the object code. 239 | 240 | 5. A program that contains no derivative of any portion of the 241 | Library, but is designed to work with the Library by being compiled or 242 | linked with it, is called a "work that uses the Library". Such a 243 | work, in isolation, is not a derivative work of the Library, and 244 | therefore falls outside the scope of this License. 245 | 246 | However, linking a "work that uses the Library" with the Library 247 | creates an executable that is a derivative of the Library (because it 248 | contains portions of the Library), rather than a "work that uses the 249 | library". The executable is therefore covered by this License. 250 | Section 6 states terms for distribution of such executables. 251 | 252 | When a "work that uses the Library" uses material from a header file 253 | that is part of the Library, the object code for the work may be a 254 | derivative work of the Library even though the source code is not. 255 | Whether this is true is especially significant if the work can be 256 | linked without the Library, or if the work is itself a library. The 257 | threshold for this to be true is not precisely defined by law. 258 | 259 | If such an object file uses only numerical parameters, data 260 | structure layouts and accessors, and small macros and small inline 261 | functions (ten lines or less in length), then the use of the object 262 | file is unrestricted, regardless of whether it is legally a derivative 263 | work. (Executables containing this object code plus portions of the 264 | Library will still fall under Section 6.) 265 | 266 | Otherwise, if the work is a derivative of the Library, you may 267 | distribute the object code for the work under the terms of Section 6. 268 | Any executables containing that work also fall under Section 6, 269 | whether or not they are linked directly with the Library itself. 270 | 271 | 6. As an exception to the Sections above, you may also combine or 272 | link a "work that uses the Library" with the Library to produce a 273 | work containing portions of the Library, and distribute that work 274 | under terms of your choice, provided that the terms permit 275 | modification of the work for the customer's own use and reverse 276 | engineering for debugging such modifications. 277 | 278 | You must give prominent notice with each copy of the work that the 279 | Library is used in it and that the Library and its use are covered by 280 | this License. You must supply a copy of this License. If the work 281 | during execution displays copyright notices, you must include the 282 | copyright notice for the Library among them, as well as a reference 283 | directing the user to the copy of this License. Also, you must do one 284 | of these things: 285 | 286 | a) Accompany the work with the complete corresponding 287 | machine-readable source code for the Library including whatever 288 | changes were used in the work (which must be distributed under 289 | Sections 1 and 2 above); and, if the work is an executable linked 290 | with the Library, with the complete machine-readable "work that 291 | uses the Library", as object code and/or source code, so that the 292 | user can modify the Library and then relink to produce a modified 293 | executable containing the modified Library. (It is understood 294 | that the user who changes the contents of definitions files in the 295 | Library will not necessarily be able to recompile the application 296 | to use the modified definitions.) 297 | 298 | b) Use a suitable shared library mechanism for linking with the 299 | Library. A suitable mechanism is one that (1) uses at run time a 300 | copy of the library already present on the user's computer system, 301 | rather than copying library functions into the executable, and (2) 302 | will operate properly with a modified version of the library, if 303 | the user installs one, as long as the modified version is 304 | interface-compatible with the version that the work was made with. 305 | 306 | c) Accompany the work with a written offer, valid for at 307 | least three years, to give the same user the materials 308 | specified in Subsection 6a, above, for a charge no more 309 | than the cost of performing this distribution. 310 | 311 | d) If distribution of the work is made by offering access to copy 312 | from a designated place, offer equivalent access to copy the above 313 | specified materials from the same place. 314 | 315 | e) Verify that the user has already received a copy of these 316 | materials or that you have already sent this user a copy. 317 | 318 | For an executable, the required form of the "work that uses the 319 | Library" must include any data and utility programs needed for 320 | reproducing the executable from it. However, as a special exception, 321 | the materials to be distributed need not include anything that is 322 | normally distributed (in either source or binary form) with the major 323 | components (compiler, kernel, and so on) of the operating system on 324 | which the executable runs, unless that component itself accompanies 325 | the executable. 326 | 327 | It may happen that this requirement contradicts the license 328 | restrictions of other proprietary libraries that do not normally 329 | accompany the operating system. Such a contradiction means you cannot 330 | use both them and the Library together in an executable that you 331 | distribute. 332 | 333 | 7. You may place library facilities that are a work based on the 334 | Library side-by-side in a single library together with other library 335 | facilities not covered by this License, and distribute such a combined 336 | library, provided that the separate distribution of the work based on 337 | the Library and of the other library facilities is otherwise 338 | permitted, and provided that you do these two things: 339 | 340 | a) Accompany the combined library with a copy of the same work 341 | based on the Library, uncombined with any other library 342 | facilities. This must be distributed under the terms of the 343 | Sections above. 344 | 345 | b) Give prominent notice with the combined library of the fact 346 | that part of it is a work based on the Library, and explaining 347 | where to find the accompanying uncombined form of the same work. 348 | 349 | 8. You may not copy, modify, sublicense, link with, or distribute 350 | the Library except as expressly provided under this License. Any 351 | attempt otherwise to copy, modify, sublicense, link with, or 352 | distribute the Library is void, and will automatically terminate your 353 | rights under this License. However, parties who have received copies, 354 | or rights, from you under this License will not have their licenses 355 | terminated so long as such parties remain in full compliance. 356 | 357 | 9. You are not required to accept this License, since you have not 358 | signed it. However, nothing else grants you permission to modify or 359 | distribute the Library or its derivative works. These actions are 360 | prohibited by law if you do not accept this License. Therefore, by 361 | modifying or distributing the Library (or any work based on the 362 | Library), you indicate your acceptance of this License to do so, and 363 | all its terms and conditions for copying, distributing or modifying 364 | the Library or works based on it. 365 | 366 | 10. Each time you redistribute the Library (or any work based on the 367 | Library), the recipient automatically receives a license from the 368 | original licensor to copy, distribute, link with or modify the Library 369 | subject to these terms and conditions. You may not impose any further 370 | restrictions on the recipients' exercise of the rights granted herein. 371 | You are not responsible for enforcing compliance by third parties with 372 | this License. 373 | 374 | 11. If, as a consequence of a court judgment or allegation of patent 375 | infringement or for any other reason (not limited to patent issues), 376 | conditions are imposed on you (whether by court order, agreement or 377 | otherwise) that contradict the conditions of this License, they do not 378 | excuse you from the conditions of this License. If you cannot 379 | distribute so as to satisfy simultaneously your obligations under this 380 | License and any other pertinent obligations, then as a consequence you 381 | may not distribute the Library at all. For example, if a patent 382 | license would not permit royalty-free redistribution of the Library by 383 | all those who receive copies directly or indirectly through you, then 384 | the only way you could satisfy both it and this License would be to 385 | refrain entirely from distribution of the Library. 386 | 387 | If any portion of this section is held invalid or unenforceable under any 388 | particular circumstance, the balance of the section is intended to apply, 389 | and the section as a whole is intended to apply in other circumstances. 390 | 391 | It is not the purpose of this section to induce you to infringe any 392 | patents or other property right claims or to contest validity of any 393 | such claims; this section has the sole purpose of protecting the 394 | integrity of the free software distribution system which is 395 | implemented by public license practices. Many people have made 396 | generous contributions to the wide range of software distributed 397 | through that system in reliance on consistent application of that 398 | system; it is up to the author/donor to decide if he or she is willing 399 | to distribute software through any other system and a licensee cannot 400 | impose that choice. 401 | 402 | This section is intended to make thoroughly clear what is believed to 403 | be a consequence of the rest of this License. 404 | 405 | 12. If the distribution and/or use of the Library is restricted in 406 | certain countries either by patents or by copyrighted interfaces, the 407 | original copyright holder who places the Library under this License may add 408 | an explicit geographical distribution limitation excluding those countries, 409 | so that distribution is permitted only in or among countries not thus 410 | excluded. In such case, this License incorporates the limitation as if 411 | written in the body of this License. 412 | 413 | 13. The Free Software Foundation may publish revised and/or new 414 | versions of the Lesser General Public License from time to time. 415 | Such new versions will be similar in spirit to the present version, 416 | but may differ in detail to address new problems or concerns. 417 | 418 | Each version is given a distinguishing version number. If the Library 419 | specifies a version number of this License which applies to it and 420 | "any later version", you have the option of following the terms and 421 | conditions either of that version or of any later version published by 422 | the Free Software Foundation. If the Library does not specify a 423 | license version number, you may choose any version ever published by 424 | the Free Software Foundation. 425 | 426 | 14. If you wish to incorporate parts of the Library into other free 427 | programs whose distribution conditions are incompatible with these, 428 | write to the author to ask for permission. For software which is 429 | copyrighted by the Free Software Foundation, write to the Free 430 | Software Foundation; we sometimes make exceptions for this. Our 431 | decision will be guided by the two goals of preserving the free status 432 | of all derivatives of our free software and of promoting the sharing 433 | and reuse of software generally. 434 | 435 | NO WARRANTY 436 | 437 | 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO 438 | WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. 439 | EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR 440 | OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY 441 | KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE 442 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 443 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE 444 | LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME 445 | THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 446 | 447 | 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN 448 | WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY 449 | AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU 450 | FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR 451 | CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE 452 | LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING 453 | RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A 454 | FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF 455 | SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 456 | DAMAGES. 457 | 458 | END OF TERMS AND CONDITIONS 459 | 460 | How to Apply These Terms to Your New Libraries 461 | 462 | If you develop a new library, and you want it to be of the greatest 463 | possible use to the public, we recommend making it free software that 464 | everyone can redistribute and change. You can do so by permitting 465 | redistribution under these terms (or, alternatively, under the terms of the 466 | ordinary General Public License). 467 | 468 | To apply these terms, attach the following notices to the library. It is 469 | safest to attach them to the start of each source file to most effectively 470 | convey the exclusion of warranty; and each file should have at least the 471 | "copyright" line and a pointer to where the full notice is found. 472 | 473 | 474 | Copyright (C) 475 | 476 | This library is free software; you can redistribute it and/or 477 | modify it under the terms of the GNU Lesser General Public 478 | License as published by the Free Software Foundation; either 479 | version 2.1 of the License, or (at your option) any later version. 480 | 481 | This library is distributed in the hope that it will be useful, 482 | but WITHOUT ANY WARRANTY; without even the implied warranty of 483 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 484 | Lesser General Public License for more details. 485 | 486 | You should have received a copy of the GNU Lesser General Public 487 | License along with this library; if not, write to the Free Software 488 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 489 | 490 | Also add information on how to contact you by electronic and paper mail. 491 | 492 | You should also get your employer (if you work as a programmer) or your 493 | school, if any, to sign a "copyright disclaimer" for the library, if 494 | necessary. Here is a sample; alter the names: 495 | 496 | Yoyodyne, Inc., hereby disclaims all copyright interest in the 497 | library `Frob' (a library for tweaking knobs) written by James Random Hacker. 498 | 499 | , 1 April 1990 500 | Ty Coon, President of Vice 501 | 502 | That's all there is to it! -------------------------------------------------------------------------------- /minimapstyle.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Minimap QtCreator plugin. 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 2.1 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not see 16 | http://www.gnu.org/licenses/lgpl-2.1.html. 17 | 18 | Copyright (c) 2017, emJay Software Consulting AB, See AUTHORS for details. 19 | */ 20 | 21 | #include "minimapstyle.h" 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | 43 | #include "minimapconstants.h" 44 | #include "minimapsettings.h" 45 | 46 | namespace Minimap { 47 | namespace Internal { 48 | namespace { 49 | const QRgb black = QColor(Qt::black).rgb(); 50 | const QRgb red = QColor(Qt::red).rgb(); 51 | const QRgb green = QColor(Qt::darkGreen).rgb(); 52 | 53 | inline QColor blendColors(const QColor &a, const QColor &b) 54 | { 55 | int c = qMin(255, a.cyan() + b.cyan()); 56 | int m = qMin(255, a.magenta() + b.magenta()); 57 | int y = qMin(255, a.yellow() + b.yellow()); 58 | int k = qMin(255, a.black() + b.black()); 59 | return QColor::fromCmyk(c, m, y, k); 60 | } 61 | 62 | inline bool updatePixel(QRgb *scanLine, 63 | bool blend, 64 | const QChar &c, 65 | int &x, 66 | int w, 67 | int tab, 68 | const QColor &bg, 69 | const QColor &fg) 70 | { 71 | if (c == QChar::Tabulation) { 72 | for (int i = 0; i < tab; ++i) { 73 | if (!blend) { 74 | scanLine[x++] = bg.rgb(); 75 | } 76 | if (x >= w) { 77 | return false; 78 | } 79 | } 80 | } else { 81 | bool isSpace = c.isSpace(); 82 | if (blend && !isSpace) { 83 | QColor result = blendColors(fg.toCmyk(), QColor(scanLine[x]).toCmyk()).toRgb(); 84 | scanLine[x++] = result.rgb(); 85 | } else { 86 | scanLine[x++] = isSpace ? bg.rgb() : fg.rgb(); 87 | } 88 | if (x >= w) { 89 | return false; 90 | } 91 | } 92 | return true; 93 | } 94 | 95 | inline void merge(QColor &bg, QColor &fg, const QTextCharFormat &f) 96 | { 97 | if (f.background().style() != Qt::NoBrush) { 98 | bg = f.background().color(); 99 | } 100 | if (f.foreground().style() != Qt::NoBrush) { 101 | fg = f.foreground().color(); 102 | } 103 | } 104 | } // namespace 105 | 106 | class MinimapStyleObject : public QObject 107 | { 108 | public: 109 | MinimapStyleObject(TextEditor::BaseTextEditor *editor) 110 | : QObject(editor->editorWidget()) 111 | , m_theme(Utils::creatorTheme()) 112 | , m_editor(editor->editorWidget()) 113 | , m_update(false) 114 | , m_isDragging(false) 115 | { 116 | m_editor->installEventFilter(this); 117 | if (!m_editor->textDocument()->document()->isEmpty()) { 118 | init(); 119 | } else { 120 | connect(m_editor->textDocument()->document(), 121 | &QTextDocument::contentsChanged, 122 | this, 123 | &MinimapStyleObject::contentsChanged); 124 | } 125 | } 126 | 127 | ~MinimapStyleObject() { m_editor->removeEventFilter(this); } 128 | 129 | bool eventFilter(QObject *watched, QEvent *event) 130 | { 131 | if (watched == m_editor && event->type() == QEvent::Resize) { 132 | deferedUpdate(); 133 | return false; 134 | } 135 | 136 | if (watched == m_editor->verticalScrollBar()) { 137 | if (event->type() == QEvent::MouseButtonPress) { 138 | QMouseEvent *mouseEvent = static_cast(event); 139 | if (mouseEvent->button() == Qt::LeftButton) { 140 | bool centerOnClick = MinimapSettings::centerOnClick(); 141 | bool showTooltip = MinimapSettings::showLineTooltip(); 142 | 143 | if (centerOnClick) { 144 | m_isDragging = true; 145 | m_lastMousePos = mouseEvent->pos(); 146 | centerViewportOnMousePosition(mouseEvent->pos()); 147 | m_editor->verticalScrollBar()->setMouseTracking(true); 148 | } 149 | 150 | if (showTooltip) { 151 | showLineRangeTooltip(mouseEvent->globalPosition().toPoint()); 152 | } 153 | 154 | return centerOnClick; 155 | } 156 | } else if (event->type() == QEvent::MouseButtonRelease) { 157 | QMouseEvent *mouseEvent = static_cast(event); 158 | if (mouseEvent->button() == Qt::LeftButton) { 159 | bool wasHandled = false; 160 | 161 | if (m_isDragging && MinimapSettings::centerOnClick()) { 162 | m_isDragging = false; 163 | m_editor->verticalScrollBar()->setMouseTracking(false); 164 | wasHandled = true; 165 | } 166 | 167 | if (MinimapSettings::showLineTooltip()) { 168 | QToolTip::hideText(); 169 | } 170 | 171 | return wasHandled; 172 | } 173 | } else if (event->type() == QEvent::MouseMove) { 174 | QMouseEvent *mouseEvent = static_cast(event); 175 | bool wasHandled = false; 176 | 177 | if (m_isDragging && MinimapSettings::centerOnClick()) { 178 | m_lastMousePos = mouseEvent->pos(); 179 | centerViewportOnMousePosition(mouseEvent->pos()); 180 | wasHandled = true; 181 | } 182 | 183 | if (MinimapSettings::showLineTooltip() && 184 | (m_isDragging || mouseEvent->buttons() & Qt::LeftButton)) { 185 | showLineRangeTooltip(mouseEvent->globalPosition().toPoint()); 186 | } 187 | 188 | return wasHandled; 189 | } 190 | } 191 | 192 | return false; 193 | } 194 | 195 | int width() const 196 | { 197 | int w = m_editor->extraArea() ? m_editor->extraArea()->width() : 0; 198 | return qMin(m_editor->width() - w, 199 | MinimapSettings::width() + Constants::MINIMAP_EXTRA_AREA_WIDTH); 200 | } 201 | 202 | const QRect &groove() const { return m_groove; } 203 | 204 | const QRect &addPage() const { return m_addPage; } 205 | 206 | const QRect &subPage() const { return m_subPage; } 207 | 208 | const QRect &slider() const { return m_slider; } 209 | 210 | int lineCount() const { return m_lineCount; } 211 | 212 | qreal factor() const { return m_factor; } 213 | 214 | const QColor &background() const { return m_backgroundColor; } 215 | 216 | const QColor &foreground() const { return m_foregroundColor; } 217 | 218 | const QColor &overlay() const { return m_overlayColor; } 219 | 220 | TextEditor::TextEditorWidget *editor() const { return m_editor; } 221 | 222 | private: 223 | void init() 224 | { 225 | QScrollBar *scrollbar = m_editor->verticalScrollBar(); 226 | scrollbar->setProperty(Constants::MINIMAP_STYLE_OBJECT_PROPERTY, 227 | QVariant::fromValue(this)); 228 | 229 | scrollbar->installEventFilter(this); 230 | 231 | connect(m_editor->textDocument(), 232 | &TextEditor::TextDocument::fontSettingsChanged, 233 | this, 234 | &MinimapStyleObject::fontSettingsChanged); 235 | connect(m_editor->document()->documentLayout(), 236 | &QAbstractTextDocumentLayout::documentSizeChanged, 237 | this, 238 | &MinimapStyleObject::deferedUpdate); 239 | connect(m_editor->document()->documentLayout(), 240 | &QAbstractTextDocumentLayout::update, 241 | this, 242 | &MinimapStyleObject::deferedUpdate); 243 | connect(MinimapSettings::instance(), 244 | &MinimapSettings::enabledChanged, 245 | this, 246 | &MinimapStyleObject::deferedUpdate); 247 | connect(MinimapSettings::instance(), 248 | &MinimapSettings::widthChanged, 249 | this, 250 | &MinimapStyleObject::deferedUpdate); 251 | connect(MinimapSettings::instance(), 252 | &MinimapSettings::lineCountThresholdChanged, 253 | this, 254 | &MinimapStyleObject::deferedUpdate); 255 | connect(MinimapSettings::instance(), 256 | &MinimapSettings::alphaChanged, 257 | this, 258 | &MinimapStyleObject::fontSettingsChanged); 259 | connect(MinimapSettings::instance(), 260 | &MinimapSettings::centerOnClickChanged, 261 | this, 262 | &MinimapStyleObject::centerOnClickChanged); 263 | connect(MinimapSettings::instance(), 264 | &MinimapSettings::showLineTooltipChanged, 265 | this, 266 | &MinimapStyleObject::showLineTooltipChanged); 267 | connect(scrollbar, 268 | &QAbstractSlider::valueChanged, 269 | this, 270 | &MinimapStyleObject::updateSubControlRects); 271 | connect(MinimapSettings::instance(), 272 | &MinimapSettings::pixelsPerLineChanged, 273 | this, 274 | &MinimapStyleObject::deferedUpdate); 275 | 276 | fontSettingsChanged(); 277 | } 278 | 279 | void centerViewportOnMousePosition(const QPoint &mousePos) 280 | { 281 | QScrollBar *scrollbar = m_editor->verticalScrollBar(); 282 | 283 | int mouseY = mousePos.y(); 284 | int minimapHeight = scrollbar->height(); 285 | 286 | // Calculate the actual height that contains code content in the minimap 287 | // This matches the logic used in drawMinimap() 288 | qreal factor = m_factor; 289 | int actualContentHeight; 290 | 291 | if (factor < 1.0) { 292 | // When zoomed out, content is scaled to fit 293 | actualContentHeight = qRound(m_lineCount * factor); 294 | } else { 295 | // When 1:1 or zoomed in, each line takes 1 pixel 296 | actualContentHeight = qMin(m_lineCount, minimapHeight); 297 | } 298 | 299 | int targetLine; 300 | 301 | // Check if mouse is within the actual code area 302 | if (mouseY <= actualContentHeight) { 303 | // Mouse is within code area - calculate proportionally 304 | qreal lineRatio = static_cast(mouseY) / actualContentHeight; 305 | targetLine = qMax(1, qRound(lineRatio * m_lineCount)); 306 | } else { 307 | // Mouse is in empty area below code - go to end of document 308 | targetLine = m_lineCount; 309 | } 310 | 311 | // Calculate the viewport height in lines 312 | int viewportHeight = m_editor->viewport()->height(); 313 | int lineHeight = m_editor->fontMetrics().lineSpacing(); 314 | int linesPerPage = viewportHeight / lineHeight; 315 | 316 | // Center the viewport on the target line 317 | int centerLine = targetLine - (linesPerPage / 2); 318 | centerLine = qMax(1, qMin(centerLine, qMax(1, m_lineCount - linesPerPage + 1))); 319 | 320 | // Convert back to scroll value (0-based for scroll position) 321 | int maxScrollValue = scrollbar->maximum(); 322 | if (maxScrollValue > 0) { 323 | int maxCenterLine = qMax(1, m_lineCount - linesPerPage + 1); 324 | if (maxCenterLine > 1) { 325 | qreal scrollRatio = static_cast(centerLine - 1) / (maxCenterLine - 1); 326 | int targetScrollValue = qRound(scrollRatio * maxScrollValue); 327 | targetScrollValue = qMax(0, qMin(targetScrollValue, maxScrollValue)); 328 | scrollbar->setValue(targetScrollValue); 329 | } else { 330 | scrollbar->setValue(0); 331 | } 332 | } 333 | } 334 | 335 | void centerOnClickChanged() 336 | { 337 | QScrollBar *scrollbar = m_editor->verticalScrollBar(); 338 | // Always keep event filter installed since we need it for tooltips too 339 | scrollbar->installEventFilter(this); 340 | 341 | if (!MinimapSettings::centerOnClick()) { 342 | m_isDragging = false; 343 | scrollbar->setMouseTracking(false); 344 | // Only hide tooltip if tooltip setting is also disabled 345 | if (!MinimapSettings::showLineTooltip()) { 346 | QToolTip::hideText(); 347 | } 348 | } 349 | } 350 | 351 | void showLineTooltipChanged() 352 | { 353 | if (!MinimapSettings::showLineTooltip()) { 354 | QToolTip::hideText(); 355 | } 356 | } 357 | 358 | void showLineRangeTooltip(const QPoint &globalPos) 359 | { 360 | QPair visibleRange = getVisibleLineRange(); 361 | int s = visibleRange.first; 362 | int e = visibleRange.second; 363 | 364 | QString tooltipText = QString("
%1

%2
").arg(s).arg(e); 365 | QToolTip::showText(globalPos, tooltipText, m_editor->verticalScrollBar()); 366 | } 367 | 368 | QPair getVisibleLineRange() const 369 | { 370 | QRect viewport = m_editor->viewport()->rect(); 371 | 372 | QTextCursor topCursor = m_editor->cursorForPosition(QPoint(0, 0)); 373 | 374 | QTextCursor bottomCursor = m_editor->cursorForPosition(QPoint(0, viewport.height() - 1)); 375 | 376 | // Convert to line numbers (1-based for user display) 377 | int firstVisibleLine = topCursor.blockNumber() + 1; 378 | int lastVisibleLine = bottomCursor.blockNumber() + 1; 379 | 380 | firstVisibleLine = qMax(1, firstVisibleLine); 381 | lastVisibleLine = qMax(firstVisibleLine, lastVisibleLine); 382 | lastVisibleLine = qMin(lastVisibleLine, m_lineCount); 383 | 384 | return QPair(firstVisibleLine, lastVisibleLine); 385 | } 386 | 387 | void contentsChanged() 388 | { 389 | disconnect(m_editor->textDocument()->document(), 390 | &QTextDocument::contentsChanged, 391 | this, 392 | &MinimapStyleObject::contentsChanged); 393 | init(); 394 | } 395 | 396 | void fontSettingsChanged() 397 | { 398 | const TextEditor::FontSettings &settings = m_editor->textDocument()->fontSettings(); 399 | m_backgroundColor = settings.formatFor(TextEditor::C_TEXT).background(); 400 | if (!m_backgroundColor.isValid()) { 401 | m_backgroundColor = m_theme->color(Utils::Theme::BackgroundColorNormal); 402 | } 403 | m_foregroundColor = settings.formatFor(TextEditor::C_TEXT).foreground(); 404 | if (!m_foregroundColor.isValid()) { 405 | m_foregroundColor = m_theme->color(Utils::Theme::TextColorNormal); 406 | } 407 | if (m_backgroundColor.value() < 128) { 408 | m_overlayColor = QColor(Qt::white); 409 | } else { 410 | m_overlayColor = QColor(Qt::black); 411 | } 412 | m_overlayColor.setAlpha(MinimapSettings::alpha()); 413 | deferedUpdate(); 414 | } 415 | 416 | void deferedUpdate() 417 | { 418 | if (m_update) { 419 | return; 420 | } 421 | m_update = true; 422 | QTimer::singleShot(0, this, &MinimapStyleObject::update); 423 | } 424 | 425 | void update() 426 | { 427 | QScrollBar *scrollbar = m_editor->verticalScrollBar(); 428 | 429 | m_lineCount = qMax(m_editor->document()->blockCount(), 1) 430 | * MinimapSettings::instance()->pixelsPerLine(); 431 | 432 | int w = scrollbar->width(); 433 | int h = scrollbar->height(); 434 | m_factor = m_lineCount <= h ? 1.0 : h / static_cast(m_lineCount); 435 | int width = this->width(); 436 | m_groove = QRect(width, 0, w - width, qMin(m_lineCount, h)); 437 | updateSubControlRects(); 438 | scrollbar->updateGeometry(); 439 | m_update = false; 440 | } 441 | 442 | void updateSubControlRects() 443 | { 444 | QScrollBar *scrollbar = m_editor->verticalScrollBar(); 445 | 446 | if (m_lineCount <= 0) { 447 | m_addPage = QRect(); 448 | m_subPage = QRect(); 449 | m_slider = QRect(); 450 | return; 451 | } 452 | 453 | int viewportHeight = m_editor->viewport()->height(); 454 | int lineHeight = m_editor->fontMetrics().lineSpacing(); 455 | int actualLinesPerPage = qMax(1, viewportHeight / lineHeight) 456 | * MinimapSettings::instance()->pixelsPerLine(); 457 | 458 | int viewPortLineCount = qRound(m_factor * actualLinesPerPage); 459 | viewPortLineCount = qMax(1, qMin(viewPortLineCount, m_groove.height())); 460 | 461 | int w = scrollbar->width(); 462 | int h = scrollbar->height(); 463 | int value = scrollbar->value(); 464 | int min = scrollbar->minimum(); 465 | int max = scrollbar->maximum(); 466 | 467 | int actualContentHeight; 468 | if (m_factor < 1.0) { 469 | // When zoomed out: content is scaled, use the last drawn line position 470 | actualContentHeight = qRound((m_lineCount - 1) * m_factor) + 1; 471 | } else { 472 | // When 1:1 or zoomed in: each line takes 1 pixel 473 | actualContentHeight = m_lineCount; 474 | } 475 | actualContentHeight = qMin(actualContentHeight, h); 476 | 477 | int realValue = 0; 478 | if (max > min && actualContentHeight > viewPortLineCount) { 479 | qreal scrollRatio = static_cast(value - min) / (max - min); 480 | int maxSliderTop = actualContentHeight - viewPortLineCount; 481 | realValue = qRound(scrollRatio * maxSliderTop); 482 | realValue = qMax(0, qMin(realValue, maxSliderTop)); 483 | } 484 | 485 | if (realValue + viewPortLineCount > actualContentHeight) { 486 | realValue = actualContentHeight - viewPortLineCount; 487 | } 488 | realValue = qMax(0, realValue); 489 | 490 | m_addPage = (realValue + viewPortLineCount < h) ? QRect(0, 491 | realValue + viewPortLineCount, 492 | w, 493 | h - realValue - viewPortLineCount) 494 | : QRect(); 495 | m_subPage = (realValue > 0) ? QRect(0, 0, w, realValue) : QRect(); 496 | m_slider = QRect(0, realValue, w, viewPortLineCount); 497 | 498 | scrollbar->update(); 499 | } 500 | 501 | Utils::Theme *m_theme; 502 | TextEditor::TextEditorWidget *m_editor; 503 | qreal m_factor; 504 | int m_lineCount; 505 | QRect m_groove, m_addPage, m_subPage, m_slider; 506 | QColor m_backgroundColor, m_foregroundColor, m_overlayColor; 507 | bool m_update; 508 | bool m_isDragging; 509 | QPoint m_lastMousePos; 510 | }; 511 | 512 | MinimapStyle::MinimapStyle(QStyle *style) : QProxyStyle(style) {} 513 | 514 | void MinimapStyle::drawComplexControl(ComplexControl control, 515 | const QStyleOptionComplex *option, 516 | QPainter *painter, 517 | const QWidget *widget) const 518 | { 519 | if (widget && control == QStyle::CC_ScrollBar && MinimapSettings::enabled()) { 520 | QVariant v = widget->property(Constants::MINIMAP_STYLE_OBJECT_PROPERTY); 521 | if (v.isValid()) { 522 | MinimapStyleObject *o = static_cast(v.value()); 523 | int lineCount = o->lineCount(); 524 | if (lineCount > 0 && lineCount <= MinimapSettings::lineCountThreshold()) { 525 | if (drawMinimap(option, painter, widget, o)) { 526 | return; 527 | } 528 | } 529 | } 530 | } 531 | QProxyStyle::drawComplexControl(control, option, painter, widget); 532 | } 533 | 534 | QStyle::SubControl MinimapStyle::hitTestComplexControl(ComplexControl control, 535 | const QStyleOptionComplex *option, 536 | const QPoint &pos, 537 | const QWidget *widget) const 538 | { 539 | if (widget && control == QStyle::CC_ScrollBar && MinimapSettings::enabled()) { 540 | QVariant v = widget->property(Constants::MINIMAP_STYLE_OBJECT_PROPERTY); 541 | if (v.isValid()) { 542 | MinimapStyleObject *o = static_cast(v.value()); 543 | int lineCount = o->lineCount(); 544 | if (lineCount > 0 && lineCount <= MinimapSettings::lineCountThreshold()) { 545 | // If center-on-click is enabled, we handle mouse events differently 546 | if (MinimapSettings::centerOnClick()) { 547 | return SC_ScrollBarGroove; 548 | } 549 | 550 | SubControl sc = SC_None; 551 | if (const QStyleOptionSlider *scrollbar = 552 | qstyleoption_cast(option)) { 553 | QRect r; 554 | uint ctrl = SC_ScrollBarAddLine; 555 | while (ctrl <= SC_ScrollBarGroove) { 556 | r = subControlRect(control, scrollbar, QStyle::SubControl(ctrl), widget); 557 | if (r.isValid() && r.contains(pos)) { 558 | sc = QStyle::SubControl(ctrl); 559 | break; 560 | } 561 | ctrl <<= 1; 562 | } 563 | } 564 | return sc; 565 | } 566 | } 567 | } 568 | return QProxyStyle::hitTestComplexControl(control, option, pos, widget); 569 | } 570 | 571 | int MinimapStyle::pixelMetric(PixelMetric metric, 572 | const QStyleOption *option, 573 | const QWidget *widget) const 574 | { 575 | if (widget && metric == QStyle::PM_ScrollBarExtent && MinimapSettings::enabled()) { 576 | int w = QProxyStyle::pixelMetric(metric, option, widget); 577 | QVariant v = widget->property(Constants::MINIMAP_STYLE_OBJECT_PROPERTY); 578 | if (v.isValid()) { 579 | MinimapStyleObject *o = static_cast(v.value()); 580 | int lineCount = o->lineCount(); 581 | if (lineCount > 0 && lineCount <= MinimapSettings::lineCountThreshold()) { 582 | w += o->width(); 583 | } 584 | } 585 | return w; 586 | } 587 | return QProxyStyle::pixelMetric(metric, option, widget); 588 | } 589 | 590 | QRect MinimapStyle::subControlRect(ComplexControl cc, 591 | const QStyleOptionComplex *opt, 592 | SubControl sc, 593 | const QWidget *widget) const 594 | { 595 | if (widget && cc == QStyle::CC_ScrollBar && MinimapSettings::enabled()) { 596 | QVariant v = widget->property(Constants::MINIMAP_STYLE_OBJECT_PROPERTY); 597 | if (v.isValid()) { 598 | MinimapStyleObject *o = static_cast(v.value()); 599 | int lineCount = o->lineCount(); 600 | if (lineCount > 0 && lineCount <= MinimapSettings::lineCountThreshold()) { 601 | switch (sc) { 602 | case QStyle::SC_ScrollBarGroove: 603 | return o->groove(); 604 | case QStyle::SC_ScrollBarAddPage: 605 | return o->addPage(); 606 | case QStyle::SC_ScrollBarSubPage: 607 | return o->subPage(); 608 | case QStyle::SC_ScrollBarSlider: 609 | return o->slider(); 610 | default: 611 | return QRect(); 612 | } 613 | } 614 | } 615 | } 616 | return QProxyStyle::subControlRect(cc, opt, sc, widget); 617 | } 618 | 619 | bool MinimapStyle::drawMinimap(const QStyleOptionComplex *option, 620 | QPainter *painter, 621 | const QWidget *widget, 622 | MinimapStyleObject *o) const 623 | { 624 | if (TextEditor::TextEditorSettings::displaySettings().m_textWrapping) { 625 | return false; 626 | } 627 | const QScrollBar *scrollbar = qobject_cast(widget); 628 | if (!scrollbar) { 629 | return false; 630 | } 631 | int h = o->editor()->size().height(); 632 | qreal factor = o->factor(); 633 | if (factor < 1.0) { 634 | h = o->lineCount(); 635 | } 636 | qreal step = 1 / factor; 637 | QColor baseBg = o->background(); 638 | QColor baseFg = o->foreground(); 639 | int w = o->width() - Constants::MINIMAP_EXTRA_AREA_WIDTH; 640 | if (w <= 0 || h <= 0) { 641 | return false; 642 | } 643 | QImage image(o->width(), h * MinimapSettings::instance()->pixelsPerLine(), QImage::Format_RGB32); 644 | image.fill(baseBg); 645 | QTextDocument *doc = o->editor()->document(); 646 | TextEditor::TextDocumentLayout *documentLayout = qobject_cast( 647 | doc->documentLayout()); 648 | int tab = o->editor()->textDocument()->tabSettings().m_tabSize; 649 | int y(0); 650 | int i(0); 651 | qreal r(0.0); 652 | bool codeFoldingVisible = o->editor()->codeFoldingVisible(); 653 | bool revisionsVisible = o->editor()->revisionsVisible(); 654 | bool folded(false); 655 | int revision(0); 656 | for (QTextBlock b = doc->begin(); b.isValid() && y < h; b = b.next()) { 657 | bool updateY(true); 658 | if (b.isVisible()) { 659 | if (qRound(r) != i++) { 660 | updateY = false; 661 | } else { 662 | r += step; 663 | } 664 | } else { 665 | continue; 666 | } 667 | if (codeFoldingVisible && !folded) { 668 | folded = TextEditor::TextBlockUserData::isFolded(b); 669 | } 670 | if (revisionsVisible) { 671 | if (b.revision() != documentLayout->lastSaveRevision) { 672 | if (revision < 1 && b.revision() < 0) { 673 | revision = 1; 674 | } else if (revision < 2) { 675 | revision = 2; 676 | } 677 | } 678 | } 679 | int x(0); 680 | bool cont(true); 681 | QRgb *scanLine = reinterpret_cast(image.scanLine(y * MinimapSettings::instance()->pixelsPerLine())); 682 | QVector formats = b.layout()->formats(); 683 | std::sort(formats.begin(), 684 | formats.end(), 685 | [](const QTextLayout::FormatRange &r1, const QTextLayout::FormatRange &r2) { 686 | if (r1.start < r2.start) { 687 | return true; 688 | } else if (r1.start > r2.start) { 689 | return false; 690 | } 691 | return r1.length < r2.length; 692 | }); 693 | QColor bBg = baseBg; 694 | QColor bFg = baseFg; 695 | merge(bBg, bFg, b.charFormat()); 696 | auto it2 = formats.begin(); 697 | for (QTextBlock::iterator it = b.begin(); !(it.atEnd()); ++it) { 698 | QTextFragment f = it.fragment(); 699 | if (f.isValid()) { 700 | QColor fBg = bBg; 701 | QColor fFg = bFg; 702 | merge(fBg, fFg, f.charFormat()); 703 | for (const QChar &c : f.text()) { 704 | QColor bg = fBg; 705 | QColor fg = fFg; 706 | it2 = std::find_if(it2, formats.end(), [&x](const QTextLayout::FormatRange &r) { 707 | return x >= r.start && x < r.start + r.length; 708 | }); 709 | if (it2 != formats.end()) { 710 | merge(bg, fg, it2->format); 711 | } 712 | cont = updatePixel(&scanLine[Constants::MINIMAP_EXTRA_AREA_WIDTH], 713 | !updateY, 714 | c, 715 | x, 716 | w, 717 | tab, 718 | bg, 719 | fg); 720 | if (!cont) { 721 | break; 722 | } 723 | } 724 | if (!cont) { 725 | break; 726 | } 727 | } else { 728 | cont = false; 729 | break; 730 | } 731 | } 732 | 733 | 734 | int originalY = y; 735 | if (updateY) { 736 | ++y; 737 | if (revision == 1) { 738 | scanLine[1] = green; 739 | scanLine[2] = green; 740 | } else if (revision == 2) { 741 | scanLine[1] = red; 742 | scanLine[2] = red; 743 | } 744 | if (folded) { 745 | scanLine[4] = black; 746 | scanLine[5] = black; 747 | } 748 | folded = false; 749 | revision = 0; 750 | } 751 | 752 | // repeat the line on the next lines to give every line a height of 753 | // (pixelsPerLine - 1), resulting in a 1px gap between lines 754 | for (int duplicationLineY = 1; 755 | duplicationLineY < MinimapSettings::instance()->pixelsPerLine() - 1; 756 | ++duplicationLineY) { 757 | QRgb *targetScanLine = reinterpret_cast(image.scanLine( 758 | originalY * MinimapSettings::instance()->pixelsPerLine() + duplicationLineY)); 759 | 760 | memcpy(targetScanLine, scanLine, image.bytesPerLine()); 761 | } 762 | } 763 | painter->save(); 764 | painter->fillRect(option->rect, baseBg); 765 | painter->drawImage(option->rect, image, option->rect); 766 | painter->setPen(Qt::NoPen); 767 | painter->setBrush(o->overlay()); 768 | QRect rect = subControlRect(QStyle::CC_ScrollBar, option, QStyle::SC_ScrollBarSlider, widget) 769 | .intersected(option->rect); 770 | painter->drawRect(rect); 771 | 772 | QPen splitter; 773 | splitter.setStyle(Qt::SolidLine); 774 | splitter.setColor(splitterColor()); 775 | painter->setPen(splitter); 776 | painter->drawLine(option->rect.topLeft(), option->rect.bottomLeft()); 777 | 778 | painter->restore(); 779 | return true; 780 | } 781 | 782 | QColor MinimapStyle::splitterColor() const 783 | { 784 | return m_splitterColor; 785 | } 786 | 787 | void MinimapStyle::setSplitterColor(const QColor &splitterColor) 788 | { 789 | m_splitterColor = splitterColor; 790 | } 791 | 792 | QObject *MinimapStyle::createMinimapStyleObject(TextEditor::BaseTextEditor *editor) 793 | { 794 | return new MinimapStyleObject(editor); 795 | } 796 | } // namespace Internal 797 | } // namespace Minimap 798 | --------------------------------------------------------------------------------