OpenMS  2.7.0
GUIHelpers.h
Go to the documentation of this file.
1 // --------------------------------------------------------------------------
2 // OpenMS -- Open-Source Mass Spectrometry
3 // --------------------------------------------------------------------------
4 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
5 // ETH Zurich, and Freie Universitaet Berlin 2002-2021.
6 //
7 // This software is released under a three-clause BSD license:
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of any author or any participating institution
14 // may be used to endorse or promote products derived from this software
15 // without specific prior written permission.
16 // For a full list of authors, refer to the file AUTHORS.
17 // --------------------------------------------------------------------------
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
22 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // --------------------------------------------------------------------------
31 // $Maintainer: Chris Bielow $
32 // $Authors: Chris Bielow $
33 // --------------------------------------------------------------------------
34 
35 #pragma once
36 
37 // OpenMS_GUI config
38 #include <OpenMS/VISUAL/OpenMS_GUIConfig.h>
40 
41 // declare Qt classes OUTSIDE of namespace OpenMS!
42 class QString;
43 class QStringList;
44 class QPainter;
45 class QPoint;
46 
47 #include <QColor>
48 #include <QCursor>
49 #include <QFont>
50 
51 #include <array>
52 
53 namespace OpenMS
54 {
58  namespace GUIHelpers
59  {
60 
63  void openFolder(const QString& folder);
64 
66  void startTOPPView(const QStringList& args);
67 
70  void openURL(const QString& target);
71 
84  void drawText(QPainter& painter, const QStringList& text, const QPoint& where, const QColor col_fg = QColor("invalid"), const QColor col_bg = QColor("invalid"), const QFont& f = QFont("Courier"));
85 
86 
91  QRectF getTextDimension(const QStringList& text, const QFont& font, int& line_spacing);
92 
93 
103  {
104  public:
106  explicit OverlapDetector(int levels);
107 
110  size_t placeItem(double x_start, double x_end);
111 
112  private:
113  std::vector<double> rows_;
114  };
115 
119  class GUILock
120  {
121  public:
125 
127  GUILock(const GUILock& rhs) = delete;
128  GUILock(GUILock&& rhs) = delete;
129  GUILock& operator=(const GUILock& rhs) = delete;
130 
133 
135  void lock();
137  void unlock();
138 
139  private:
140  QWidget* locked_widget_{ nullptr };
141  bool currently_locked_{ false };
142  bool was_enabled_{ true };
143  };
144 
148  {
149  public:
150  struct Distinct
151  {
152  enum NAMES
153  {
169  };
170 
171  const std::array<QColor, NAMES::SIZE_OF_NAMES> values = { { Qt::red,
172  Qt::blue,
173  Qt::green,
174  QColor(129, 74, 25) /*brown*/,
175  QColor(129, 38, 192) /*purple*/,
176  Qt::lightGray,
177  QColor(129,197,122) /*lightGreen*/,
178  QColor(157,175,255) /*lightBlue*/,
179  Qt::cyan,
180  QColor(255,146,51) /*orange*/,
181  Qt::yellow,
182  QColor(233,222,187) /*tan*/,
183  QColor(255,205,243) /*pink*/,
184  Qt::darkGray } };
185  };
186 
188  template<class COLOR_CLASS>
189  static QColor getColor(uint32_t index)
190  {
191  // cycle if necessary
192  if (index >= COLOR_CLASS::NAMES::SIZE_OF_NAMES) index = index % COLOR_CLASS::NAMES::SIZE_OF_NAMES;
193  return COLOR_CLASS().values[index];
194  }
195  }; // ColorBrewer
196 
197  StringList convert(const QStringList& in);
198  QStringList convert(const StringList& in);
199 
200  }; // GUIHelpers
201 }
Definition: GUIHelpers.h:148
static QColor getColor(uint32_t index)
get a certain color. If index is larger than the maximum color, modulo operator will applied (cycling...
Definition: GUIHelpers.h:189
RAII class to disable the GUI and set a busy cursor and go back to the orignal state when this class ...
Definition: GUIHelpers.h:120
GUILock & operator=(const GUILock &rhs)=delete
GUILock(const GUILock &rhs)=delete
no copy/assignment allowed
~GUILock()
D'tor: unlocks the GUI (does nothing if already unlocked)
bool was_enabled_
Definition: GUIHelpers.h:142
void unlock()
manually unlock the GUI (does nothing if already unlocked)
QWidget * locked_widget_
Definition: GUIHelpers.h:140
void lock()
manually lock the GUI (does nothing if already locked)
bool currently_locked_
Definition: GUIHelpers.h:141
GUILock(GUILock &&rhs)=delete
Given a set of levels (rows), try to add items at to topmost row which does not overlap an already pl...
Definition: GUIHelpers.h:103
std::vector< double > rows_
Definition: GUIHelpers.h:113
OverlapDetector(int levels)
C'tor: number of levels must be >=1.
size_t placeItem(double x_start, double x_end)
std::vector< String > StringList
Vector of String.
Definition: ListUtils.h:70
void drawText(QPainter &painter, const QStringList &text, const QPoint &where, const QColor col_fg=QColor("invalid"), const QColor col_bg=QColor("invalid"), const QFont &f=QFont("Courier"))
draw a multi-line text at coordinates XY using a specific font and color
StringList convert(const QStringList &in)
QRectF getTextDimension(const QStringList &text, const QFont &font, int &line_spacing)
Obtains the bounding rectangle of a text (useful to determine overlaps etc)
void startTOPPView(const QStringList &args)
Open TOPPView (e.g. from within TOPPAS)
void openURL(const QString &target)
void openFolder(const QString &folder)
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
Definition: GUIHelpers.h:151
const std::array< QColor, NAMES::SIZE_OF_NAMES > values
Definition: GUIHelpers.h:171
NAMES
Definition: GUIHelpers.h:153
@ Purple
Definition: GUIHelpers.h:158
@ DarkGrey
Definition: GUIHelpers.h:167
@ LightBlue
Definition: GUIHelpers.h:161
@ Pink
Definition: GUIHelpers.h:166
@ LightGreen
Definition: GUIHelpers.h:160
@ LightGrey
Definition: GUIHelpers.h:159
@ Orange
Definition: GUIHelpers.h:163
@ Brown
Definition: GUIHelpers.h:157
@ Cyan
Definition: GUIHelpers.h:162
@ Tan
Definition: GUIHelpers.h:165
@ Yellow
Definition: GUIHelpers.h:164
@ Green
Definition: GUIHelpers.h:156
@ Red
Definition: GUIHelpers.h:154
@ SIZE_OF_NAMES
Definition: GUIHelpers.h:168
@ Blue
Definition: GUIHelpers.h:155