24 #include <QApplication>
26 #include <QContextMenuEvent>
29 #include <KActionCollection>
30 #include <KXMLGUIClient>
31 #include <KColorDialog>
32 #include <KInputDialog>
35 #include <KMime/KMimeMessage>
39 using namespace Akonadi;
43 : EntityTreeView( xmlGuiClient, parent ), m_xmlGuiClient( xmlGuiClient )
50 QMenu *popup =
new QMenu(
this);
52 QModelIndexList rows = selectionModel()->selectedRows();
54 const bool noselection = rows.isEmpty();
55 const bool singleselection = rows.size() == 1;
56 const bool multiselection = rows.size() > 1;
58 popup->addAction(m_xmlGuiClient->actionCollection()->action(QLatin1String(
"new_book")));
59 if ( singleselection )
61 popup->addAction(m_xmlGuiClient->actionCollection()->action(QLatin1String(
"new_page")));
62 popup->addAction(m_xmlGuiClient->actionCollection()->action(QLatin1String(
"rename_entry")));
64 popup->addAction(m_xmlGuiClient->actionCollection()->action(QLatin1String(
"copy_link_address")));
65 popup->addAction(m_xmlGuiClient->actionCollection()->action(QLatin1String(
"change_color")));
67 popup->addAction(m_xmlGuiClient->actionCollection()->action(QLatin1String(
"sort_children_alpha")));
68 popup->addAction(m_xmlGuiClient->actionCollection()->action(QLatin1String(
"sort_children_by_date")));
71 popup->addAction(m_xmlGuiClient->actionCollection()->action(QLatin1String(
"save_to")));
72 popup->addSeparator();
74 popup->addAction(m_xmlGuiClient->actionCollection()->action(QLatin1String(
"lock")));
75 popup->addAction(m_xmlGuiClient->actionCollection()->action(QLatin1String(
"unlock")));
77 if ( singleselection )
79 Item item = rows.at( 0 ).data( KJotsModel::ItemRole ).value<Item>();
80 if ( item.isValid() ) {
81 popup->addAction(m_xmlGuiClient->actionCollection()->action(QLatin1String(
"del_page")));
83 popup->addAction(m_xmlGuiClient->actionCollection()->action(QLatin1String(
"del_folder")));
88 popup->addAction(m_xmlGuiClient->actionCollection()->action(QLatin1String(
"del_mult")));
90 popup->exec( event->globalPos() );
97 connect(m_xmlGuiClient->actionCollection()->action(QLatin1String(
"rename_entry")), SIGNAL(triggered()),
99 connect(m_xmlGuiClient->actionCollection()->action(QLatin1String(
"copy_link_address")), SIGNAL(triggered()),
101 connect(m_xmlGuiClient->actionCollection()->action(QLatin1String(
"change_color")), SIGNAL(triggered()),
109 QModelIndexList selection = selectionModel()->selectedRows();
111 int selectionSize = selection.size();
112 if ( selectionSize > 1 ) {
113 caption = i18n(
"Multiple selections");
114 }
else if ( selectionSize == 1 ) {
115 QModelIndex index = selection.at( 0 );
116 while ( index.isValid() ) {
117 QModelIndex parentBook = index.parent();
119 if ( parentBook.isValid() ) {
120 caption = sep + index.data().toString() + caption;
122 caption = index.data().toString() + caption;
132 QModelIndexList rows = selectionModel()->selectedRows();
134 if ( rows.size() != 1 )
137 QModelIndex idx = rows.at( 0 );
139 QString title = idx.data().toString();
141 Item item = idx.data( KJotsModel::ItemRole ).value<Item>();
142 if ( item.isValid() )
144 Q_ASSERT( item.hasPayload<KMime::Message::Ptr>() );
145 if ( !item.hasPayload<KMime::Message::Ptr>() )
149 QString name = KInputDialog::getText( i18n(
"Rename Page" ),
150 i18n(
"Page title:" ), title, &ok,
this );
153 model()->setData( idx, name, Qt::EditRole );
157 Collection col = idx.data( KJotsModel::CollectionRole ).value<Collection>();
158 Q_ASSERT( col.isValid() );
163 QString name = KInputDialog::getText( i18n(
"Rename Book" ),
164 i18n(
"Book name:" ), title, &ok,
this );
167 model()->setData( idx, name, Qt::EditRole );
172 QModelIndexList rows = selectionModel()->selectedRows();
174 if ( rows.size() != 1 )
177 QModelIndex idx = rows.at( 0 );
179 QString title = idx.data().toString();
181 Item item = idx.data( KJotsModel::ItemRole ).value<Item>();
183 QMimeData *mimeData =
new QMimeData();
186 if ( item.isValid() )
188 Q_ASSERT( item.hasPayload<KMime::Message::Ptr>() );
189 if ( !item.hasPayload<KMime::Message::Ptr>() )
192 link = QString::fromLatin1(
"<a href=\"%1\">%2</a>" ).arg( item.url().url() ).arg( title );
194 Collection col = idx.data( KJotsModel::CollectionRole ).value<Collection>();
196 Q_ASSERT(col.isValid());
200 link = QString::fromLatin1(
"<a href=\"%1\">%2</a>" ).arg( col.url().url() ).arg( title );
203 mimeData->setData( QLatin1String(
"kjots/internal_link"), link.toUtf8() );
204 mimeData->setText( title );
205 QApplication::clipboard()->setMimeData( mimeData );
211 int result = KColorDialog::getColor( myColor );
213 if ( result != KColorDialog::Accepted )
216 QModelIndexList rows = selectionModel()->selectedRows();
218 foreach (
const QModelIndex &idx, rows )
220 model()->setData(idx, myColor, Qt::BackgroundRole );
224 #include "kjotstreeview.moc"
QString captionForSelection(const QString &sep) const
KJotsTreeView(KXMLGUIClient *xmlGuiClient, QWidget *parent=0)
virtual void contextMenuEvent(QContextMenuEvent *event)
void delayedInitialization()