• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • applications API Reference
  • KDE Home
  • Contact Us
 

Kate

  • kde-4.14
  • applications
  • kate
  • part
  • snippet
snippet.cpp
Go to the documentation of this file.
1 /* This file is part of the Kate project.
2  * Based on the snippet plugin from KDevelop 4.
3  *
4  * Copyright (C) 2007 Robert Gruber <rgruber@users.sourceforge.net>
5  * Copyright (C) 2010 Milian Wolff <mail@milianw.de>
6  * Copyright (C) 2012 Christoph Cullmann <cullmann@kde.org>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public License
19  * along with this library; see the file COPYING.LIB. If not, write to
20  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21  * Boston, MA 02110-1301, USA.
22  */
23 
24 #include "snippet.h"
25 
26 #include <KLocalizedString>
27 #include <KIcon>
28 
29 #include <KColorScheme>
30 
31 #include "katesnippetglobal.h"
32 #include <KActionCollection>
33 #include <KAction>
34 #include <KParts/MainWindow>
35 
36 Snippet::Snippet()
37  : QStandardItem(i18n("<empty snippet>")), m_action(0)
38 {
39  setIcon(KIcon("text-plain"));
40 }
41 
42 Snippet::~Snippet()
43 {
44  delete m_action;
45 }
46 
47 QString Snippet::snippet() const
48 {
49  return m_snippet;
50 }
51 
52 void Snippet::setSnippet(const QString& snippet)
53 {
54  m_snippet = snippet;
55 }
56 
57 QString Snippet::prefix() const
58 {
59  return m_prefix;
60 }
61 
62 void Snippet::setPrefix(const QString& prefix)
63 {
64  m_prefix = prefix;
65 }
66 
67 QString Snippet::postfix() const
68 {
69  return m_postfix;
70 }
71 
72 void Snippet::setPostfix(const QString& postfix)
73 {
74  m_postfix = postfix;
75 }
76 
77 QString Snippet::arguments() const
78 {
79  return m_arguments;
80 }
81 
82 void Snippet::setArguments(const QString& arguments)
83 {
84  m_arguments = arguments;
85 }
86 
87 KAction* Snippet::action()
88 {
90  if ( !m_action ) {
91  static int actionCount = 0;
92  m_action = new KAction(QString("insertSnippet%1").arg(actionCount), KateSnippetGlobal::self());
93  m_action->setData(QVariant::fromValue<Snippet*>(this));
94  KateSnippetGlobal::self()->connect(m_action, SIGNAL(triggered()),
95  KateSnippetGlobal::self(), SLOT(insertSnippetFromActionData()));
96 
97 #if 0 // FIXME
98  // action needs to be added to a widget before it can work...
99  KDevelop::ICore::self()->uiController()->activeMainWindow()->addAction(m_action);
100 #endif
101  }
102  m_action->setText(i18n("insert snippet %1", text()));
103  return m_action;
104 }
105 
106 QVariant Snippet::data(int role) const
107 {
108  if ( role == Qt::ToolTipRole ) {
109  return m_snippet;
110  } else if ( (role == Qt::ForegroundRole || role == Qt::BackgroundRole) && parent()->checkState() != Qt::Checked ) {
112  KColorScheme scheme(QPalette::Disabled, KColorScheme::View);
113  if (role == Qt::ForegroundRole) {
114  return scheme.foreground(KColorScheme::ActiveText).color();
115  } else {
116  return scheme.background(KColorScheme::ActiveBackground).color();
117  }
118  }
119  return QStandardItem::data(role);
120 }
Snippet::setSnippet
void setSnippet(const QString &snippet)
Sets the actual contents of this snippet.
Definition: snippet.cpp:52
Kate::Script::i18n
QScriptValue i18n(QScriptContext *context, QScriptEngine *engine)
i18n("text", arguments [optional])
Definition: katescripthelpers.cpp:186
QStandardItem::setIcon
void setIcon(const QIcon &icon)
Snippet::setArguments
void setArguments(const QString &arguments)
Sets the display arguments of this snippet.
Definition: snippet.cpp:82
Snippet::setPrefix
void setPrefix(const QString &prefix)
Sets the display prefix of this snippet.
Definition: snippet.cpp:62
Snippet::action
KAction * action()
Action to trigger insertion of this snippet.
Definition: snippet.cpp:87
QStandardItem::text
QString text() const
QStandardItem::checkState
Qt::CheckState checkState() const
Snippet::data
virtual QVariant data(int role=Qt::UserRole+1) const
Definition: snippet.cpp:106
KateSnippetGlobal::self
static KateSnippetGlobal * self()
Definition: katesnippetglobal.h:54
katesnippetglobal.h
QStandardItem::parent
QStandardItem * parent() const
Snippet::setPostfix
void setPostfix(const QString &postfix)
Sets the display postfix of this snippet.
Definition: snippet.cpp:72
QString
Snippet::prefix
QString prefix() const
Returns the display prefix of this snippet.
Definition: snippet.cpp:57
Snippet::Snippet
Snippet()
Construct an empty snippet.
Definition: snippet.cpp:36
Snippet::snippet
QString snippet() const
Returns the actual contents of this snippet.
Definition: snippet.cpp:47
KAction
Snippet::~Snippet
~Snippet()
Definition: snippet.cpp:42
QStandardItem
Snippet::arguments
QString arguments() const
Returns the display arguments of this snippet.
Definition: snippet.cpp:77
Snippet::postfix
QString postfix() const
Returns the display postfix of this snippet.
Definition: snippet.cpp:67
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QStandardItem::data
virtual QVariant data(int role) const
snippet.h
QVariant
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sat May 9 2020 03:56:59 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Kate

Skip menu "Kate"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

applications API Reference

Skip menu "applications API Reference"
  •   kate
  •       kate
  •   KTextEditor
  •   Kate
  • Konsole

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal