本文整理汇总了C++中ToolButton::setData方法的典型用法代码示例。如果您正苦于以下问题:C++ ToolButton::setData方法的具体用法?C++ ToolButton::setData怎么用?C++ ToolButton::setData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ToolButton
的用法示例。
在下文中一共展示了ToolButton::setData方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: bookmarkEdited
void BookmarksToolbar::bookmarkEdited(const BookmarksModel::Bookmark &before, const BookmarksModel::Bookmark &after)
{
if (before.folder == QLatin1String("bookmarksToolbar") && after.folder != QLatin1String("bookmarksToolbar")) {
// Editing from toolbar folder to other folder -> Remove bookmark
removeBookmark(before);
}
else if (before.folder != QLatin1String("bookmarksToolbar") && after.folder == QLatin1String("bookmarksToolbar")) {
// Editing from other folder to toolbar folder -> Add bookmark
addBookmark(after);
}
else {
// Editing bookmark already in toolbar
for (int i = 0; i < m_layout->count(); i++) {
ToolButton* button = qobject_cast<ToolButton*>(m_layout->itemAt(i)->widget());
if (!button) {
continue;
}
Bookmark book = button->data().value<Bookmark>();
if (book == before) {
QString title = after.title;
if (title.length() > 15) {
title.truncate(13);
title += "..";
}
QVariant v;
v.setValue<Bookmark>(after);
button->setText(title);
button->setData(v);
button->setIcon(qIconProvider->iconFromImage(after.image));
button->setToolTip(after.url.toEncoded());
return;
}
}
}
}
示例2: addBookmark
void BookmarksToolbar::addBookmark(const BookmarksModel::Bookmark &bookmark)
{
if (bookmark.folder != "bookmarksToolbar") {
return;
}
QString title = bookmark.title;
if (title.length() > 15) {
title.truncate(13);
title += "..";
}
QVariant v;
v.setValue<Bookmark>(bookmark);
ToolButton* button = new ToolButton(this);
button->setText(title);
button->setData(v);
button->setIcon(bookmark.icon);
button->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
button->setToolTip(bookmark.url.toEncoded());
button->setAutoRaise(true);
button->setWhatsThis(bookmark.title);
button->setContextMenuPolicy(Qt::CustomContextMenu);
connect(button, SIGNAL(clicked()), this, SLOT(loadClickedBookmark()));
connect(button, SIGNAL(middleMouseClicked()), this, SLOT(loadClickedBookmarkInNewTab()));
connect(button, SIGNAL(controlClicked()), this, SLOT(loadClickedBookmarkInNewTab()));
connect(button, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showBookmarkContextMenu(QPoint)));
int indexForBookmark = indexOfLastBookmark();
m_layout->insertWidget(indexForBookmark, button);
QSqlQuery query;
query.prepare("UPDATE bookmarks SET toolbar_position=? WHERE id=?");
query.addBindValue(indexForBookmark);
query.addBindValue(bookmark.id);
mApp->dbWriter()->executeQuery(query);
}
示例3: refreshBookmarks
void BookmarksToolbar::refreshBookmarks()
{
QSqlQuery query;
query.exec("SELECT id, title, url, icon FROM bookmarks WHERE folder='bookmarksToolbar' ORDER BY toolbar_position");
while (query.next()) {
Bookmark bookmark;
bookmark.id = query.value(0).toInt();
bookmark.title = query.value(1).toString();
bookmark.url = query.value(2).toUrl();
bookmark.icon = IconProvider::iconFromBase64(query.value(3).toByteArray());
bookmark.folder = "bookmarksToolbar";
QString title = bookmark.title;
if (title.length() > 15) {
title.truncate(13);
title += "..";
}
QVariant v;
v.setValue<Bookmark>(bookmark);
ToolButton* button = new ToolButton(this);
button->setText(title);
button->setData(v);
button->setIcon(bookmark.icon);
button->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
button->setToolTip(bookmark.url.toEncoded());
button->setWhatsThis(bookmark.title);
button->setAutoRaise(true);
button->setContextMenuPolicy(Qt::CustomContextMenu);
connect(button, SIGNAL(clicked()), this, SLOT(loadClickedBookmark()));
connect(button, SIGNAL(middleMouseClicked()), this, SLOT(loadClickedBookmarkInNewTab()));
connect(button, SIGNAL(controlClicked()), this, SLOT(loadClickedBookmarkInNewTab()));
connect(button, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showBookmarkContextMenu(QPoint)));
m_layout->addWidget(button);
}
query.exec("SELECT name FROM folders WHERE subfolder='yes'");
while (query.next()) {
ToolButton* b = new ToolButton(this);
b->setPopupMode(QToolButton::InstantPopup);
b->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
b->setIcon(style()->standardIcon(QStyle::SP_DirIcon));
b->setText(query.value(0).toString());
Menu* menu = new Menu(query.value(0).toString());
b->setMenu(menu);
connect(menu, SIGNAL(aboutToShow()), this, SLOT(aboutToShowFolderMenu()));
m_layout->addWidget(b);
}
m_mostVis = new ToolButton(this);
m_mostVis->setPopupMode(QToolButton::InstantPopup);
m_mostVis->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
m_mostVis->setIcon(style()->standardIcon(QStyle::SP_DirIcon));
m_mostVis->setText(tr("Most visited"));
m_mostVis->setToolTip(tr("Sites you visited the most"));
m_menuMostVisited = new Menu();
m_mostVis->setMenu(m_menuMostVisited);
connect(m_menuMostVisited, SIGNAL(aboutToShow()), this, SLOT(refreshMostVisited()));
m_layout->addWidget(m_mostVis);
m_layout->addStretch();
m_mostVis->setVisible(m_bookmarksModel->isShowingMostVisited());
}