LeechCraft Monocle  0.6.70-18450-gabe19ee3b0
Modular document viewer for LeechCraft
ilink.h
Go to the documentation of this file.
1 /**********************************************************************
2  * LeechCraft - modular cross-platform feature rich internet client.
3  * Copyright (C) 2006-2014 Georg Rudoy
4  *
5  * Distributed under the Boost Software License, Version 1.0.
6  * (See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
7  **********************************************************************/
8 
9 #pragma once
10 
11 #include <memory>
12 #include <QObject>
13 #include <QMetaType>
14 #include <QUrl>
15 #include "coordsbase.h"
16 
17 namespace LC::Monocle
18 {
25  enum class LinkType
26  {
37  PageLink,
38 
41  URL,
42 
45  Command,
46 
49  OtherLink
50  };
51 
55  {
59 
62  std::optional<PageRelativeRectBase> TargetArea_ {};
63 
66  std::optional<double> Zoom_ {};
67 
68  bool operator== (const NavigationAction&) const = default;
69  bool operator< (const NavigationAction& other) const
70  {
71  const auto toTuple = [] (const NavigationAction& act)
72  {
73  qreal x {};
74  qreal y {};
75  qreal w {};
76  qreal h {};
77  act.TargetArea_.value_or (PageRelativeRectBase {}).ToRectF ().getRect (&x, &y, &w, &h);
78  return std::tie (act.PageNumber_, x, y, w, h); // don't care about the zoom
79  };
80 
81  return toTuple (*this) < toTuple (other);
82  }
83  };
84 
88  {
91  QString TargetDocument_ {};
92 
96  };
97 
98  struct UrlAction
99  {
100  QUrl Url_;
101  };
102 
103  using CustomAction = std::function<void ()>;
104 
105  struct NoAction {};
106 
107  using LinkAction = std::variant<NoAction, NavigationAction, ExternalNavigationAction, UrlAction, CustomAction>;
108 
113  class ILink
114  {
115  public:
118  virtual ~ILink () = default;
119 
124  virtual LinkType GetLinkType () const = 0;
125 
133  virtual PageRelativeRectBase GetArea () const = 0;
134 
137  virtual LinkAction GetLinkAction () const = 0;
138 
141  virtual QString GetToolTip () const
142  {
143  return {};
144  }
145  };
146  typedef std::shared_ptr<ILink> ILink_ptr;
147 }
148 
149 Q_DECLARE_INTERFACE (LC::Monocle::ILink, "org.LeechCraft.Monocle.ILink/1.0")
std::optional< PageRelativeRectBase > TargetArea_
Definition: ilink.h:62
std::shared_ptr< ILink > ILink_ptr
Definition: ilink.h:146
A link to an URL.
NavigationAction DocumentNavigation_
Definition: ilink.h:95
A link action that represents navigating to a different document.
Definition: ilink.h:87
Some standard command like printing.
LinkType
Describes various link types known to Monocle.
Definition: ilink.h:25
A link action that represents navigating inside the document.
Definition: ilink.h:54
std::optional< double > Zoom_
Definition: ilink.h:66
bool operator<(const NavigationAction &other) const
Definition: ilink.h:69
std::variant< NoAction, NavigationAction, ExternalNavigationAction, UrlAction, CustomAction > LinkAction
Definition: ilink.h:107
bool operator==(const NavigationAction &) const =default
std::function< void()> CustomAction
Definition: ilink.h:103