Document webshortcutmodel
This commit is contained in:
committed by
Carl Schwan
parent
983d4c9db2
commit
0cab7b1c85
@@ -8,43 +8,60 @@
|
|||||||
|
|
||||||
struct KWebShortcutModelPrivate;
|
struct KWebShortcutModelPrivate;
|
||||||
|
|
||||||
//! List model of web shortcuts for a a specified selectedText.
|
/**
|
||||||
//!
|
* @class KWebShortcutModel
|
||||||
//! This can be used as following in your QML code
|
*
|
||||||
//!
|
* This class defines the model for listing web shortcuts for a specified selectedText.
|
||||||
//! ```qml
|
*
|
||||||
//! QQC2.Menu {
|
* This can be used as follows in your QML code:
|
||||||
//! id: webshortcutmenu
|
*
|
||||||
//! title: i18n("Search for '%1'", webshortcutmodel.trunkatedSearchText)
|
* ```qml
|
||||||
//! property bool isVisible: selectedText && selectedText.length > 0 && webshortcutmodel.enabled
|
* QQC2.Menu {
|
||||||
//! Component.onCompleted: webshortcutmenu.parent.visible = isVisible
|
* id: webshortcutmenu
|
||||||
//! onIsVisibleChanged: webshortcutmenu.parent.visible = isVisible
|
*
|
||||||
//! Instantiator {
|
* title: i18n("Search for '%1'", webshortcutmodel.trunkatedSearchText)
|
||||||
//! model: WebShortcutModel {
|
* property bool isVisible: selectedText && selectedText.length > 0 && webshortcutmodel.enabled
|
||||||
//! id: webshortcutmodel
|
* Component.onCompleted: webshortcutmenu.parent.visible = isVisible
|
||||||
//! selectedText: loadRoot.selectedText
|
* onIsVisibleChanged: webshortcutmenu.parent.visible = isVisible
|
||||||
//! onOpenUrl: Qt.openUrlExternally(url)
|
* Instantiator {
|
||||||
//! }
|
* model: WebShortcutModel {
|
||||||
//! delegate: QQC2.MenuItem {
|
* id: webshortcutmodel
|
||||||
//! text: model.display
|
* selectedText: loadRoot.selectedText
|
||||||
//! icon.name: model.decoration
|
* onOpenUrl: Qt.openUrlExternally(url)
|
||||||
//! onTriggered: webshortcutmodel.trigger(model.edit)
|
* }
|
||||||
//! }
|
* delegate: QQC2.MenuItem {
|
||||||
//! onObjectAdded: webshortcutmenu.insertItem(0, object)
|
* text: model.display
|
||||||
//! }
|
* icon.name: model.decoration
|
||||||
//! QQC2.MenuSeparator {}
|
* onTriggered: webshortcutmodel.trigger(model.edit)
|
||||||
//! QQC2.MenuItem {
|
* }
|
||||||
//! text: i18n("Configure Web Shortcuts...")
|
* onObjectAdded: webshortcutmenu.insertItem(0, object)
|
||||||
//! icon.name: "configure"
|
* }
|
||||||
//! onTriggered: webshortcutmodel.configureWebShortcuts()
|
* QQC2.MenuSeparator {}
|
||||||
//! }
|
* QQC2.MenuItem {
|
||||||
//! }
|
* text: i18n("Configure Web Shortcuts...")
|
||||||
//! ```
|
* icon.name: "configure"
|
||||||
|
* onTriggered: webshortcutmodel.configureWebShortcuts()
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
class KWebShortcutModel : public QAbstractListModel
|
class KWebShortcutModel : public QAbstractListModel
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The text to find web shortcuts for.
|
||||||
|
*/
|
||||||
Q_PROPERTY(QString selectedText READ selectedText WRITE setSelectedText NOTIFY selectedTextChanged)
|
Q_PROPERTY(QString selectedText READ selectedText WRITE setSelectedText NOTIFY selectedTextChanged)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The selectedText elided at a set width.
|
||||||
|
*/
|
||||||
Q_PROPERTY(QString trunkatedSearchText READ trunkatedSearchText NOTIFY selectedTextChanged)
|
Q_PROPERTY(QString trunkatedSearchText READ trunkatedSearchText NOTIFY selectedTextChanged)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Whether web shortcuts are available.
|
||||||
|
*/
|
||||||
Q_PROPERTY(bool enabled READ enabled CONSTANT)
|
Q_PROPERTY(bool enabled READ enabled CONSTANT)
|
||||||
public:
|
public:
|
||||||
explicit KWebShortcutModel(QObject *parent = nullptr);
|
explicit KWebShortcutModel(QObject *parent = nullptr);
|
||||||
@@ -52,13 +69,35 @@ public:
|
|||||||
|
|
||||||
QString selectedText() const;
|
QString selectedText() const;
|
||||||
void setSelectedText(const QString &selectedText);
|
void setSelectedText(const QString &selectedText);
|
||||||
|
|
||||||
QString trunkatedSearchText() const;
|
QString trunkatedSearchText() const;
|
||||||
|
|
||||||
bool enabled() const;
|
bool enabled() const;
|
||||||
|
|
||||||
int rowCount(const QModelIndex &parent) const override;
|
/**
|
||||||
|
* @brief Get the given role value at the given index.
|
||||||
|
*
|
||||||
|
* @sa QAbstractItemModel::data
|
||||||
|
*/
|
||||||
QVariant data(const QModelIndex &index, int role) const override;
|
QVariant data(const QModelIndex &index, int role) const override;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Number of rows in the model.
|
||||||
|
*
|
||||||
|
* @sa QAbstractItemModel::rowCount
|
||||||
|
*/
|
||||||
|
int rowCount(const QModelIndex &parent) const override;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Trigger the openUrl signal for the given web shortcut.
|
||||||
|
*/
|
||||||
Q_INVOKABLE void trigger(const QString &data);
|
Q_INVOKABLE void trigger(const QString &data);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Request the menu for configuring web shortcut settings be opened.
|
||||||
|
*/
|
||||||
Q_INVOKABLE void configureWebShortcuts();
|
Q_INVOKABLE void configureWebShortcuts();
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void selectedTextChanged();
|
void selectedTextChanged();
|
||||||
void openUrl(const QUrl &url);
|
void openUrl(const QUrl &url);
|
||||||
|
|||||||
Reference in New Issue
Block a user