OpenMS  3.0.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-2022.
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 
42 // declare Qt classes OUTSIDE of namespace OpenMS!
43 class QPainter;
44 class QPoint;
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  {
64 
67  OPENMS_GUI_DLLAPI void openFolder(const QString& folder);
68 
70 
71  OPENMS_GUI_DLLAPI QString getSaveFilename(QWidget* parent,
72  const QString& caption,
73  const QString& dir,
74  FileTypeList supported_file_types,
75  bool add_all_filter,
76  const FileTypes::Type fallback_extension);
77 
78 
80  OPENMS_GUI_DLLAPI void startTOPPView(const QStringList& args);
81 
84  OPENMS_GUI_DLLAPI void openURL(const QString& target);
85 
98  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"),
99  const QFont& font = QFont("Courier"));
100 
101 
106  OPENMS_GUI_DLLAPI QRectF getTextDimension(const QStringList& text, const QFont& font, int& line_spacing);
107 
108 
119  class OPENMS_GUI_DLLAPI OverlapDetector
120  {
121  public:
124  explicit OverlapDetector(int levels);
125 
128  size_t placeItem(double x_start, double x_end);
129 
130  private:
131  std::vector<double> rows_;
132  };
133 
137  class OPENMS_GUI_DLLAPI GUILock
138  {
139  public:
142  GUILock(QWidget* gui);
143 
145  GUILock(const GUILock& rhs) = delete;
146  GUILock(GUILock&& rhs) = delete;
147  GUILock& operator=(const GUILock& rhs) = delete;
148 
150  ~GUILock();
151 
153  void lock();
155  void unlock();
156 
157  private:
158  QWidget* locked_widget_{ nullptr };
159  bool currently_locked_{ false };
160  bool was_enabled_{ true };
161  };
162 
166  {
167  public:
168  struct Distinct
169  {
170  enum NAMES
171  {
187  };
188 
189  const std::array<QColor, NAMES::SIZE_OF_NAMES> values = { { Qt::red,
190  Qt::blue,
191  Qt::green,
192  QColor(129, 74, 25) /*brown*/,
193  QColor(129, 38, 192) /*purple*/,
194  Qt::lightGray,
195  QColor(129,197,122) /*lightGreen*/,
196  QColor(157,175,255) /*lightBlue*/,
197  Qt::cyan,
198  QColor(255,146,51) /*orange*/,
199  Qt::yellow,
200  QColor(233,222,187) /*tan*/,
201  QColor(255,205,243) /*pink*/,
202  Qt::darkGray } };
203  };
204 
206  template<class COLOR_CLASS>
207  static QColor getColor(uint32_t index)
208  {
209  // cycle if necessary
210  if (index >= COLOR_CLASS::NAMES::SIZE_OF_NAMES) index = index % COLOR_CLASS::NAMES::SIZE_OF_NAMES;
211  return COLOR_CLASS().values[index];
212  }
213  }; // ColorBrewer
214 
215  OPENMS_GUI_DLLAPI StringList convert(const QStringList& in);
216  OPENMS_GUI_DLLAPI QStringList convert(const StringList& in);
217 
218  }; // GUIHelpers
219 }
OpenMS::GUIHelpers::openFolder
void openFolder(const QString &folder)
FileHandler.h
OpenMS::GUIHelpers::ColorBrewer::Distinct::Pink
Definition: GUIHelpers.h:184
OpenMS::GUIHelpers::getTextDimension
QRectF getTextDimension(const QStringList &text, const QFont &font, int &line_spacing)
Obtains the bounding rectangle of a text (useful to determine overlaps etc)
OpenMS::GUIHelpers::ColorBrewer::Distinct::Yellow
Definition: GUIHelpers.h:182
OpenMS::GUIHelpers::ColorBrewer::Distinct::Tan
Definition: GUIHelpers.h:183
OpenMS::GUIHelpers::ColorBrewer::Distinct::NAMES
NAMES
Definition: GUIHelpers.h:170
OpenMS::GUIHelpers::ColorBrewer::Distinct::LightBlue
Definition: GUIHelpers.h:179
OpenMS::GUIHelpers::ColorBrewer::Distinct::Orange
Definition: GUIHelpers.h:181
OpenMS::GUIHelpers::startTOPPView
void startTOPPView(const QStringList &args)
Open TOPPView (e.g. from within TOPPAS)
OpenMS::GUIHelpers::openURL
void openURL(const QString &target)
OpenMS::GUIHelpers::getSaveFilename
QString getSaveFilename(QWidget *parent, const QString &caption, const QString &dir, FileTypeList supported_file_types, bool add_all_filter, const FileTypes::Type fallback_extension)
Open a dialog to select a filename to save data to.
OpenMS::GUIHelpers::ColorBrewer
Definition: GUIHelpers.h:165
OpenMS::GUIHelpers::ColorBrewer::Distinct::Cyan
Definition: GUIHelpers.h:180
OpenMS::GUIHelpers::ColorBrewer::Distinct::SIZE_OF_NAMES
Definition: GUIHelpers.h:186
QWidget
ListUtils.h
OpenMS::GUIHelpers::OverlapDetector
A heuristic: Given a set of levels (rows), try to add items at to topmost row which does not overlap ...
Definition: GUIHelpers.h:119
OpenMS::GUIHelpers::ColorBrewer::Distinct::Purple
Definition: GUIHelpers.h:176
OpenMS
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
OpenMS::GUIHelpers::ColorBrewer::Distinct
Definition: GUIHelpers.h:168
OpenMS::GUIHelpers::ColorBrewer::Distinct::Blue
Definition: GUIHelpers.h:173
OpenMS::GUIHelpers::ColorBrewer::Distinct::LightGrey
Definition: GUIHelpers.h:177
OpenMS::GUIHelpers::ColorBrewer::Distinct::Green
Definition: GUIHelpers.h:174
OpenMS::FileTypes::Type
Type
Actual file types enum.
Definition: FileTypes.h:56
OpenMS::GUIHelpers::convert
StringList convert(const QStringList &in)
OpenMS::GUIHelpers::GUILock
RAII class to disable the GUI and set a busy cursor and go back to the original state when this class...
Definition: GUIHelpers.h:137
OpenMS::GUIHelpers::ColorBrewer::Distinct::LightGreen
Definition: GUIHelpers.h:178
OpenMS::GUIHelpers::ColorBrewer::getColor
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:207
OpenMS::StringList
std::vector< String > StringList
Vector of String.
Definition: ListUtils.h:70
OpenMS::GUIHelpers::ColorBrewer::Distinct::DarkGrey
Definition: GUIHelpers.h:185
OpenMS::GUIHelpers::OverlapDetector::rows_
std::vector< double > rows_
store the largest x_end for each row
Definition: GUIHelpers.h:131
OpenMS::GUIHelpers::ColorBrewer::Distinct::Brown
Definition: GUIHelpers.h:175
OpenMS::GUIHelpers::drawText
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
OpenMS::GUIHelpers::ColorBrewer::Distinct::Red
Definition: GUIHelpers.h:172
OpenMS::GUIHelpers::ColorBrewer::Distinct::values
const std::array< QColor, NAMES::SIZE_OF_NAMES > values
Definition: GUIHelpers.h:189
OpenMS::FileTypeList
holds a vector of known file types, e.g. as a way to specify supported input formats
Definition: FileTypes.h:149