31 #include <KPushButton>
35 #include <QtGui/QLayout>
36 #include <QtGui/QTreeView>
37 #include <QtGui/QHeaderView>
48 connect( mBookmarkListModel, SIGNAL(modelReset()),
49 SLOT(onBookmarkSelectionChanged()) );
51 QVBoxLayout* baseLayout =
new QVBoxLayout(
this );
52 baseLayout->setMargin( 0 );
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()) );
70 baseLayout->addWidget( mBookmarkListView, 10 );
73 QHBoxLayout* actionsLayout =
new QHBoxLayout();
75 const KGuiItem createBookmarkGuiItem =
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 );
85 connect( mCreateBookmarkButton, SIGNAL(clicked(
bool)),
86 SLOT(onCreateBookmarkButtonClicked()) );
87 connect( mTool, SIGNAL(canCreateBookmarkChanged(
bool)),
88 mCreateBookmarkButton, SLOT(setEnabled(
bool)) );
89 actionsLayout->addWidget( mCreateBookmarkButton );
91 const KGuiItem deleteBookmarkGuiItem =
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 );
103 actionsLayout->addStretch();
105 const KGuiItem gotoGuiItem =
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 );
117 const KGuiItem renameGuiItem =
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 );
129 baseLayout->addLayout( actionsLayout );
131 onBookmarkSelectionChanged();
135 void BookmarksView::onBookmarkDoubleClicked(
const QModelIndex& index )
137 const int column = index.column();
143 void BookmarksView::onBookmarkSelectionChanged()
145 const QItemSelectionModel* selectionModel = mBookmarkListView->selectionModel();
149 const bool hasSelection = !selectionModel->selectedIndexes().isEmpty();
150 mDeleteBookmarksButton->setEnabled( hasSelection );
152 const bool bookmarkSelected = selectionModel->isSelected( selectionModel->currentIndex() );
153 mRenameBookmarkButton->setEnabled( bookmarkSelected );
154 mGotoBookmarkButton->setEnabled( bookmarkSelected );
157 void BookmarksView::onCreateBookmarkButtonClicked()
163 if( index.isValid() )
164 mBookmarkListView->edit( index );
168 void BookmarksView::onDeleteBookmarkButtonClicked()
170 const QModelIndexList selectedRows = mBookmarkListView->selectionModel()->selectedRows();
173 foreach(
const QModelIndex& index, selectedRows )
176 bookmarksToBeDeleted.append( bookmark );
181 void BookmarksView::onGotoBookmarkButtonClicked()
183 const QModelIndex index = mBookmarkListView->selectionModel()->currentIndex();
184 if( index.isValid() )
188 void BookmarksView::onRenameBookmarkButtonClicked()
190 QModelIndex index = mBookmarkListView->selectionModel()->currentIndex();
192 if( nameIndex.isValid() )
193 mBookmarkListView->edit( nameIndex );
BookmarksView(BookmarksTool *tool, QWidget *parent=0)
QModelIndex index(const Okteta::Bookmark &bookmark, int column=BookmarkListModel::TitleColumnId) const
const Okteta::Bookmark & bookmark(const QModelIndex &index) const