OpenMS
GUIHelpers.h
Go to the documentation of this file.
1 // Copyright (c) 2002-present, The OpenMS Team -- EKU Tuebingen, ETH Zurich, and FU Berlin
2 // SPDX-License-Identifier: BSD-3-Clause
3 //
4 // --------------------------------------------------------------------------
5 // $Maintainer: Chris Bielow $
6 // $Authors: Chris Bielow $
7 // --------------------------------------------------------------------------
8 
9 #pragma once
10 
11 #include <OpenMS/VISUAL/OpenMS_GUIConfig.h>
14 
15 // declare Qt classes OUTSIDE of namespace OpenMS!
16 class QPainter;
17 class QPoint;
18 class QPointF;
19 class QRectF;
20 class QWidget;
21 
22 #include <QColor>
23 #include <QFont>
24 #include <QtCore/qcontainerfwd.h> // for QStringList
25 
26 #include <array>
27 
28 namespace OpenMS
29 {
30 
31  class FileTypeList;
32 
36  namespace GUIHelpers
37  {
40  OPENMS_GUI_DLLAPI void openFolder(const QString& folder);
41 
43 
44  OPENMS_GUI_DLLAPI QString getSaveFilename(QWidget* parent,
45  const QString& caption,
46  const QString& dir,
47  const FileTypeList& supported_file_types,
48  bool add_all_filter,
49  const FileTypes::Type fallback_extension);
50 
51 
54  OPENMS_GUI_DLLAPI bool startTOPPView(QStringList args);
55 
58  OPENMS_GUI_DLLAPI void openURL(const QString& target);
59 
72  OPENMS_GUI_DLLAPI void drawText(QPainter& painter, const QStringList& text, const QPoint& where, const QColor& col_fg = QColor("invalid"), const QColor& col_bg = QColor("invalid"),
73  const QFont& font = QFont("Courier"));
74 
75 
80  OPENMS_GUI_DLLAPI QRectF getTextDimension(const QStringList& text, const QFont& font, int& line_spacing);
81 
82 
84  OPENMS_GUI_DLLAPI QPointF nearestPoint(const QPointF& origin, const QList<QPointF>& list);
85 
92  OPENMS_GUI_DLLAPI QPointF intersectionPoint(const QRectF& rect, const QPointF& p);
93 
94 
105  class OPENMS_GUI_DLLAPI OverlapDetector
106  {
107  public:
110  explicit OverlapDetector(int levels);
111 
114  size_t placeItem(double x_start, double x_end);
115 
116  private:
117  std::vector<double> rows_;
118  };
119 
123  class OPENMS_GUI_DLLAPI GUILock
124  {
125  public:
129 
131  GUILock(const GUILock& rhs) = delete;
132  GUILock(GUILock&& rhs) = delete;
133  GUILock& operator=(const GUILock& rhs) = delete;
134 
137 
139  void lock();
141  void unlock();
142 
143  private:
144  QWidget* locked_widget_{ nullptr };
145  bool currently_locked_{ false };
146  bool was_enabled_{ true };
147  };
148 
152  {
153  public:
154  struct Distinct
155  {
156  enum NAMES
157  {
173  };
174 
175  const std::array<QColor, NAMES::SIZE_OF_NAMES> values = { { Qt::red,
176  Qt::blue,
177  Qt::green,
178  QColor(129, 74, 25) /*brown*/,
179  QColor(129, 38, 192) /*purple*/,
180  Qt::lightGray,
181  QColor(129,197,122) /*lightGreen*/,
182  QColor(157,175,255) /*lightBlue*/,
183  Qt::cyan,
184  QColor(255,146,51) /*orange*/,
185  Qt::yellow,
186  QColor(233,222,187) /*tan*/,
187  QColor(255,205,243) /*pink*/,
188  Qt::darkGray } };
189  };
190 
192  template<class COLOR_CLASS>
193  static QColor getColor(uint32_t index)
194  {
195  // cycle if necessary
196  if (index >= COLOR_CLASS::NAMES::SIZE_OF_NAMES) index = index % COLOR_CLASS::NAMES::SIZE_OF_NAMES;
197  return COLOR_CLASS().values[index];
198  }
199  }; // ColorBrewer
200 
201  OPENMS_GUI_DLLAPI StringList convert(const QStringList& in);
202  OPENMS_GUI_DLLAPI QStringList convert(const StringList& in);
203 
204  }; // GUIHelpers
205 }
holds a vector of known file types, e.g. as a way to specify supported input formats
Definition: FileTypes.h:139
Definition: GUIHelpers.h:152
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:193
RAII class to disable the GUI and set a busy cursor and go back to the original state when this class...
Definition: GUIHelpers.h:124
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)
void unlock()
manually unlock the GUI (does nothing if already unlocked)
void lock()
manually lock the GUI (does nothing if already locked)
GUILock(GUILock &&rhs)=delete
A heuristic: Given a set of levels (rows), try to add items at to topmost row which does not overlap ...
Definition: GUIHelpers.h:106
std::vector< double > rows_
store the largest x_end for each row
Definition: GUIHelpers.h:117
size_t placeItem(double x_start, double x_end)
std::vector< String > StringList
Vector of String.
Definition: ListUtils.h:44
void drawText(QPainter &painter, const QStringList &text, const QPoint &where, const QColor &col_fg=QColor("invalid"), const QColor &col_bg=QColor("invalid"), const QFont &font=QFont("Courier"))
draw a multi-line text at coordinates XY using a specific font and color
QString getSaveFilename(QWidget *parent, const QString &caption, const QString &dir, const FileTypeList &supported_file_types, bool add_all_filter, const FileTypes::Type fallback_extension)
Open a dialog to select a filename to save data to.
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)
QPointF nearestPoint(const QPointF &origin, const QList< QPointF > &list)
Returns the point in the list that is nearest to origin.
void openURL(const QString &target)
bool startTOPPView(QStringList args)
void openFolder(const QString &folder)
QPointF intersectionPoint(const QRectF &rect, const QPointF &p)
Find the point on a rectangle where a ray/line from a point p to its center would intersect at.
Main OpenMS namespace.
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
Colorizer blue
Colorizer green
Colorizer yellow
Colorizer cyan
Colorizer red
Type
Actual file types enum.
Definition: FileTypes.h:31
Definition: GUIHelpers.h:155
const std::array< QColor, NAMES::SIZE_OF_NAMES > values
Definition: GUIHelpers.h:175
NAMES
Definition: GUIHelpers.h:157
@ Purple
Definition: GUIHelpers.h:162
@ DarkGrey
Definition: GUIHelpers.h:171
@ LightBlue
Definition: GUIHelpers.h:165
@ Pink
Definition: GUIHelpers.h:170
@ LightGreen
Definition: GUIHelpers.h:164
@ LightGrey
Definition: GUIHelpers.h:163
@ Orange
Definition: GUIHelpers.h:167
@ Brown
Definition: GUIHelpers.h:161
@ Cyan
Definition: GUIHelpers.h:166
@ Tan
Definition: GUIHelpers.h:169
@ Yellow
Definition: GUIHelpers.h:168
@ Green
Definition: GUIHelpers.h:160
@ Red
Definition: GUIHelpers.h:158
@ SIZE_OF_NAMES
Definition: GUIHelpers.h:172
@ Blue
Definition: GUIHelpers.h:159