OpenMS
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-2023.
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 #include <OpenMS/VISUAL/OpenMS_GUIConfig.h>
40 
41 // declare Qt classes OUTSIDE of namespace OpenMS!
42 class QPainter;
43 class QPoint;
44 class QRectF;
45 class QString;
46 class QStringList;
47 class QWidget;
48 
49 #include <QColor>
50 #include <QFont>
51 
52 #include <array>
53 
54 namespace OpenMS
55 {
56 
57  class FileTypeList;
58 
62  namespace GUIHelpers
63  {
66  OPENMS_GUI_DLLAPI void openFolder(const QString& folder);
67 
69 
70  OPENMS_GUI_DLLAPI QString getSaveFilename(QWidget* parent,
71  const QString& caption,
72  const QString& dir,
73  const FileTypeList& supported_file_types,
74  bool add_all_filter,
75  const FileTypes::Type fallback_extension);
76 
77 
79  OPENMS_GUI_DLLAPI void startTOPPView(const QStringList& args);
80 
83  OPENMS_GUI_DLLAPI void openURL(const QString& target);
84 
97  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"),
98  const QFont& font = QFont("Courier"));
99 
100 
105  OPENMS_GUI_DLLAPI QRectF getTextDimension(const QStringList& text, const QFont& font, int& line_spacing);
106 
107 
109  OPENMS_GUI_DLLAPI QPointF nearestPoint(const QPointF& origin, const QList<QPointF>& list);
110 
117  OPENMS_GUI_DLLAPI QPointF intersectionPoint(const QRectF& rect, const QPointF& p);
118 
119 
130  class OPENMS_GUI_DLLAPI OverlapDetector
131  {
132  public:
135  explicit OverlapDetector(int levels);
136 
139  size_t placeItem(double x_start, double x_end);
140 
141  private:
142  std::vector<double> rows_;
143  };
144 
148  class OPENMS_GUI_DLLAPI GUILock
149  {
150  public:
154 
156  GUILock(const GUILock& rhs) = delete;
157  GUILock(GUILock&& rhs) = delete;
158  GUILock& operator=(const GUILock& rhs) = delete;
159 
162 
164  void lock();
166  void unlock();
167 
168  private:
169  QWidget* locked_widget_{ nullptr };
170  bool currently_locked_{ false };
171  bool was_enabled_{ true };
172  };
173 
177  {
178  public:
179  struct Distinct
180  {
181  enum NAMES
182  {
198  };
199 
200  const std::array<QColor, NAMES::SIZE_OF_NAMES> values = { { Qt::red,
201  Qt::blue,
202  Qt::green,
203  QColor(129, 74, 25) /*brown*/,
204  QColor(129, 38, 192) /*purple*/,
205  Qt::lightGray,
206  QColor(129,197,122) /*lightGreen*/,
207  QColor(157,175,255) /*lightBlue*/,
208  Qt::cyan,
209  QColor(255,146,51) /*orange*/,
210  Qt::yellow,
211  QColor(233,222,187) /*tan*/,
212  QColor(255,205,243) /*pink*/,
213  Qt::darkGray } };
214  };
215 
217  template<class COLOR_CLASS>
218  static QColor getColor(uint32_t index)
219  {
220  // cycle if necessary
221  if (index >= COLOR_CLASS::NAMES::SIZE_OF_NAMES) index = index % COLOR_CLASS::NAMES::SIZE_OF_NAMES;
222  return COLOR_CLASS().values[index];
223  }
224  }; // ColorBrewer
225 
226  OPENMS_GUI_DLLAPI StringList convert(const QStringList& in);
227  OPENMS_GUI_DLLAPI QStringList convert(const StringList& in);
228 
229  }; // GUIHelpers
230 }
holds a vector of known file types, e.g. as a way to specify supported input formats
Definition: FileTypes.h:150
Definition: GUIHelpers.h:177
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:218
RAII class to disable the GUI and set a busy cursor and go back to the original state when this class...
Definition: GUIHelpers.h:149
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:131
std::vector< double > rows_
store the largest x_end for each row
Definition: GUIHelpers.h:142
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 &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)
void startTOPPView(const QStringList &args)
Open TOPPView (e.g. from within TOPPAS)
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)
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: FeatureDeconvolution.h:48
Colorizer blue
Colorizer green
Colorizer yellow
Colorizer cyan
Colorizer red
Type
Actual file types enum.
Definition: FileTypes.h:57
Definition: GUIHelpers.h:180
const std::array< QColor, NAMES::SIZE_OF_NAMES > values
Definition: GUIHelpers.h:200
NAMES
Definition: GUIHelpers.h:182
@ Purple
Definition: GUIHelpers.h:187
@ DarkGrey
Definition: GUIHelpers.h:196
@ LightBlue
Definition: GUIHelpers.h:190
@ Pink
Definition: GUIHelpers.h:195
@ LightGreen
Definition: GUIHelpers.h:189
@ LightGrey
Definition: GUIHelpers.h:188
@ Orange
Definition: GUIHelpers.h:192
@ Brown
Definition: GUIHelpers.h:186
@ Cyan
Definition: GUIHelpers.h:191
@ Tan
Definition: GUIHelpers.h:194
@ Yellow
Definition: GUIHelpers.h:193
@ Green
Definition: GUIHelpers.h:185
@ Red
Definition: GUIHelpers.h:183
@ SIZE_OF_NAMES
Definition: GUIHelpers.h:197
@ Blue
Definition: GUIHelpers.h:184