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

okteta

  • sources
  • kde-4.12
  • kdesdk
  • okteta
  • kasten
  • controllers
  • view
  • bookmarks
bookmarksview.cpp
Go to the documentation of this file.
1 /*
2  This file is part of the Kasten Framework, made within the KDE community.
3 
4  Copyright 2009 Friedrich W. H. Kossebau <kossebau@kde.org>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Lesser General Public
8  License as published by the Free Software Foundation; either
9  version 2.1 of the License, or (at your option) version 3, or any
10  later version accepted by the membership of KDE e.V. (or its
11  successor approved by the membership of KDE e.V.), which shall
12  act as a proxy defined in Section 6 of version 3 of the license.
13 
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public
20  License along with this library. If not, see <http://www.gnu.org/licenses/>.
21 */
22 
23 #include "bookmarksview.h"
24 
25 // tool
26 #include "bookmarklistmodel.h"
27 #include "bookmarkstool.h"
28 // Okteta core
29 #include <bookmark.h>
30 // KDE
31 #include <KPushButton>
32 #include <KLocale>
33 #include <KGuiItem>
34 // Qt
35 #include <QtGui/QLayout>
36 #include <QtGui/QTreeView>
37 #include <QtGui/QHeaderView>
38 
39 
40 namespace Kasten2
41 {
42 
43 BookmarksView::BookmarksView( BookmarksTool* tool, QWidget* parent )
44  : QWidget( parent ),
45  mTool( tool )
46 {
47  mBookmarkListModel = new BookmarkListModel( mTool, this );
48  connect( mBookmarkListModel, SIGNAL(modelReset()),
49  SLOT(onBookmarkSelectionChanged()) );
50 
51  QVBoxLayout* baseLayout = new QVBoxLayout( this );
52  baseLayout->setMargin( 0 );
53 
54  // bookmarks list
55  mBookmarkListView = new QTreeView( this );
56  mBookmarkListView->setObjectName( QLatin1String( "BookmarkListView" ) );
57  mBookmarkListView->setRootIsDecorated( false );
58  mBookmarkListView->setItemsExpandable( false );
59  mBookmarkListView->setUniformRowHeights( true );
60  mBookmarkListView->setAllColumnsShowFocus( true );
61  mBookmarkListView->setSelectionMode( QAbstractItemView::ExtendedSelection );
62  mBookmarkListView->setModel( mBookmarkListModel );
63  mBookmarkListView->header()->setResizeMode( QHeaderView::Interactive );
64  connect( mBookmarkListView, SIGNAL(doubleClicked(QModelIndex)),
65  SLOT(onBookmarkDoubleClicked(QModelIndex)) );
66  connect( mBookmarkListView->selectionModel(),
67  SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
68  SLOT(onBookmarkSelectionChanged()) );
69 
70  baseLayout->addWidget( mBookmarkListView, 10 );
71 
72  // actions TODO: make this view work like the filebrowser, with actions on top?
73  QHBoxLayout* actionsLayout = new QHBoxLayout();
74 
75  const KGuiItem createBookmarkGuiItem =
76  KGuiItem( QString()/*i18n("C&opy")*/,
77  QLatin1String("bookmark-new"),
78  i18nc("@info:tooltip",
79  "Creates a new bookmark for the current cursor position."),
80  i18nc("@info:whatsthis",
81  "If you press this button, a new bookmark will be created "
82  "for the current cursor position.") );
83  mCreateBookmarkButton = new KPushButton( createBookmarkGuiItem, this );
84  mCreateBookmarkButton->setEnabled( mTool->canCreateBookmark() );
85  connect( mCreateBookmarkButton, SIGNAL(clicked(bool)),
86  SLOT(onCreateBookmarkButtonClicked()) );
87  connect( mTool, SIGNAL(canCreateBookmarkChanged(bool)),
88  mCreateBookmarkButton, SLOT(setEnabled(bool)) );
89  actionsLayout->addWidget( mCreateBookmarkButton );
90 
91  const KGuiItem deleteBookmarkGuiItem =
92  KGuiItem( QString()/*i18n("&Go to")*/,
93  QLatin1String("edit-delete"),
94  i18nc("@info:tooltip",
95  "Deletes all the selected bookmarks."),
96  i18nc("@info:whatsthis",
97  "If you press this button, all bookmarks which are "
98  "selected will be deleted.") );
99  mDeleteBookmarksButton = new KPushButton( deleteBookmarkGuiItem, this );
100  connect( mDeleteBookmarksButton, SIGNAL(clicked(bool)), SLOT(onDeleteBookmarkButtonClicked()) );
101  actionsLayout->addWidget( mDeleteBookmarksButton );
102 
103  actionsLayout->addStretch();
104 
105  const KGuiItem gotoGuiItem =
106  KGuiItem( QString()/*i18n("&Go to")*/,
107  QLatin1String("go-jump"),
108  i18nc("@info:tooltip",
109  "Moves the cursor to the selected bookmark."),
110  i18nc("@info:whatsthis",
111  "If you press this button, the cursor is moved to the position "
112  "of the bookmark which has been last selected.") );
113  mGotoBookmarkButton = new KPushButton( gotoGuiItem, this );
114  connect( mGotoBookmarkButton, SIGNAL(clicked(bool)), SLOT(onGotoBookmarkButtonClicked()) );
115  actionsLayout->addWidget( mGotoBookmarkButton );
116 
117  const KGuiItem renameGuiItem =
118  KGuiItem( QString()/*i18n("&Go to")*/,
119  QLatin1String("edit-rename"),
120  i18nc("@info:tooltip",
121  "Enables renaming of the selected bookmark."),
122  i18nc("@info:whatsthis",
123  "If you press this button, the name of the bookmark "
124  "which was last selected can be edited.") );
125  mRenameBookmarkButton = new KPushButton( renameGuiItem, this );
126  connect( mRenameBookmarkButton, SIGNAL(clicked(bool)), SLOT(onRenameBookmarkButtonClicked()) );
127  actionsLayout->addWidget( mRenameBookmarkButton );
128 
129  baseLayout->addLayout( actionsLayout );
130 
131  onBookmarkSelectionChanged();
132 }
133 
134 
135 void BookmarksView::onBookmarkDoubleClicked( const QModelIndex& index )
136 {
137  const int column = index.column();
138  const bool isOffsetColum = ( column == BookmarkListModel::OffsetColumnId );
139  if( isOffsetColum )
140  mTool->gotoBookmark( mBookmarkListModel->bookmark(index) );
141 }
142 
143 void BookmarksView::onBookmarkSelectionChanged()
144 {
145  const QItemSelectionModel* selectionModel = mBookmarkListView->selectionModel();
146 
147  // TODO: selectionModel->selectedIndexes() is a expensive operation,
148  // but with Qt 4.4.3 hasSelection() has the flaw to return true with a current index
149  const bool hasSelection = !selectionModel->selectedIndexes().isEmpty();
150  mDeleteBookmarksButton->setEnabled( hasSelection );
151 
152  const bool bookmarkSelected = selectionModel->isSelected( selectionModel->currentIndex() );
153  mRenameBookmarkButton->setEnabled( bookmarkSelected );
154  mGotoBookmarkButton->setEnabled( bookmarkSelected );
155 }
156 
157 void BookmarksView::onCreateBookmarkButtonClicked()
158 {
159  const Okteta::Bookmark bookmark = mTool->createBookmark();
160  if( bookmark.isValid() )
161  {
162  const QModelIndex index = mBookmarkListModel->index( bookmark, BookmarkListModel::TitleColumnId );
163  if( index.isValid() )
164  mBookmarkListView->edit( index );
165  }
166 }
167 
168 void BookmarksView::onDeleteBookmarkButtonClicked()
169 {
170  const QModelIndexList selectedRows = mBookmarkListView->selectionModel()->selectedRows();
171 
172  QList<Okteta::Bookmark> bookmarksToBeDeleted;
173  foreach( const QModelIndex& index, selectedRows )
174  {
175  const Okteta::Bookmark& bookmark = mBookmarkListModel->bookmark( index );
176  bookmarksToBeDeleted.append( bookmark );
177  }
178  mTool->deleteBookmarks( bookmarksToBeDeleted );
179 }
180 
181 void BookmarksView::onGotoBookmarkButtonClicked()
182 {
183  const QModelIndex index = mBookmarkListView->selectionModel()->currentIndex();
184  if( index.isValid() )
185  mTool->gotoBookmark( mBookmarkListModel->bookmark(index) );
186 }
187 
188 void BookmarksView::onRenameBookmarkButtonClicked()
189 {
190  QModelIndex index = mBookmarkListView->selectionModel()->currentIndex();
191  const QModelIndex nameIndex = index.sibling( index.row(), BookmarkListModel::TitleColumnId );
192  if( nameIndex.isValid() )
193  mBookmarkListView->edit( nameIndex );
194 }
195 
196 
197 BookmarksView::~BookmarksView() {}
198 
199 }
bookmarklistmodel.h
Kasten2::BookmarksTool::gotoBookmark
void gotoBookmark(const Okteta::Bookmark &bookmark)
Definition: bookmarkstool.cpp:165
bookmark.h
Kasten2::BookmarksTool::canCreateBookmark
bool canCreateBookmark() const
Definition: bookmarkstool.cpp:56
Kasten2::BookmarksView::BookmarksView
BookmarksView(BookmarksTool *tool, QWidget *parent=0)
Definition: bookmarksview.cpp:43
Kasten2::BookmarkListModel
Definition: bookmarklistmodel.h:43
Okteta::Bookmark
Definition: bookmark.h:38
QWidget
Kasten2::BookmarksTool::createBookmark
Okteta::Bookmark createBookmark()
Definition: bookmarkstool.cpp:129
Kasten2::BookmarkListModel::index
QModelIndex index(const Okteta::Bookmark &bookmark, int column=BookmarkListModel::TitleColumnId) const
Definition: bookmarklistmodel.cpp:171
Kasten2::BookmarksTool
Definition: bookmarkstool.h:47
Okteta::Bookmark::isValid
bool isValid() const
Definition: bookmark.h:65
Kasten2::BookmarkListModel::bookmark
const Okteta::Bookmark & bookmark(const QModelIndex &index) const
Definition: bookmarklistmodel.cpp:165
bookmarksview.h
Kasten2::BookmarksTool::deleteBookmarks
void deleteBookmarks(const QList< Okteta::Bookmark > &bookmarks)
Definition: bookmarkstool.cpp:158
Kasten2::BookmarkListModel::TitleColumnId
Definition: bookmarklistmodel.h:51
bookmarkstool.h
Kasten2::BookmarksView::~BookmarksView
virtual ~BookmarksView()
Definition: bookmarksview.cpp:197
Kasten2::BookmarkListModel::OffsetColumnId
Definition: bookmarklistmodel.h:50
QList
Definition: bookmarkable.h:29
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:04:07 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

okteta

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

kdesdk API Reference

Skip menu "kdesdk API Reference"
  • kapptemplate
  • kcachegrind
  • kompare
  • lokalize
  • okteta
  • umbrello
  •   umbrello

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