Menu::Menu(bool playBgm) { changeFontSize(64); m_cursor = new Cursor(); m_background.loadFromFile("res/GUI/menu-backgroundscroll.png", 1280, 720); m_backgroundLogo.loadFromFile("res/GUI/menu-logo.png", 500, 180); if(playBgm) { m_menuTheme.loadMusicFile("res/Music/bgm/Lifeline.ogg", false); m_menuTheme.repeatMusic(); } GLfloat offsetWidth = SCREEN_WIDTH * 0.50; m_menuState = MAIN_MENU; m_buttons.push_back(new Button(Vector2f(offsetWidth, SCREEN_HEIGHT / 2), SCREEN_WIDTH / 4, SCREEN_HEIGHT / 7, "Play Game", true)); m_buttons.push_back(new Button(Vector2f(offsetWidth, SCREEN_HEIGHT - (SCREEN_HEIGHT / 3)), SCREEN_WIDTH / 4, SCREEN_HEIGHT / 7, "Options", true)); m_buttons.push_back(new Button(Vector2f(offsetWidth, SCREEN_HEIGHT - (SCREEN_HEIGHT / 6)), SCREEN_WIDTH / 4, SCREEN_HEIGHT / 7, "Exit Game", true)); m_buttons.push_back(new Button(Vector2f(SCREEN_WIDTH * 0.1, SCREEN_HEIGHT - (SCREEN_HEIGHT / 6)), SCREEN_WIDTH / 6, SCREEN_HEIGHT / 8, "Map Editor", true)); m_optionsButtons.push_back(new Button(Vector2f(SCREEN_WIDTH * 0.50, SCREEN_HEIGHT / 2), SCREEN_WIDTH / 4, SCREEN_HEIGHT / 7, "Music: " + std::to_string(g_bgmVolume) + "%", false)); m_optionsButtons.push_back(new Button(Vector2f(SCREEN_WIDTH * 0.35, SCREEN_HEIGHT / 2), SCREEN_WIDTH / 20, SCREEN_HEIGHT / 7, "-", true)); m_optionsButtons.push_back(new Button(Vector2f(SCREEN_WIDTH * 0.65, SCREEN_HEIGHT / 2), SCREEN_WIDTH / 20, SCREEN_HEIGHT / 7, "+", true)); m_optionsButtons.push_back(new Button(Vector2f(SCREEN_WIDTH * 0.50, SCREEN_HEIGHT - (SCREEN_HEIGHT / 3)), SCREEN_WIDTH / 4, SCREEN_HEIGHT / 7, "Sound: " + std::to_string(g_sfxVolume) + "%", false)); m_optionsButtons.push_back(new Button(Vector2f(SCREEN_WIDTH * 0.35, SCREEN_HEIGHT - (SCREEN_HEIGHT / 3)), SCREEN_WIDTH / 20, SCREEN_HEIGHT / 7, "-", true)); m_optionsButtons.push_back(new Button(Vector2f(SCREEN_WIDTH * 0.65, SCREEN_HEIGHT - (SCREEN_HEIGHT / 3)), SCREEN_WIDTH / 20, SCREEN_HEIGHT / 7, "+", true)); m_optionsButtons.push_back(new Button(Vector2f(SCREEN_WIDTH * 0.10, SCREEN_HEIGHT - (SCREEN_HEIGHT / 6)), SCREEN_WIDTH / 6, SCREEN_HEIGHT / 10, "Reset Save", true)); m_optionsButtons[6]->setColor(color(255, 0, 0, 255)); m_optionsButtons.push_back(new Button(Vector2f(SCREEN_WIDTH * 0.50, SCREEN_HEIGHT - (SCREEN_HEIGHT / 6)), SCREEN_WIDTH / 6, SCREEN_HEIGHT / 7, "Home", true)); m_optionsButtons.push_back(new Button(Vector2f(SCREEN_WIDTH * 0.80, SCREEN_HEIGHT - (SCREEN_HEIGHT / 6)), SCREEN_WIDTH / 6, SCREEN_HEIGHT / 10, "Credits", true)); m_optionsButtons[8]->setColor(color(0, 0, 255, 255)); changeFontSize(16); m_backgroundAlpha = 0.5f; m_alphaChange = 0.05f; g_isPlayerDead = false; }
void ChatWidget::valueChanged( agui::Slider* source, int value ) { //slider from toolbar float val = (float)(value - source->getMinValue()); float percent = val / (float)source->getRange(); m_fontRatio = percent; DISPATCH_SCENE_EVENT (*it)->setNumericSetting("chat.game.font",m_fontRatio); changeFontSize(); }
void ChatWidget::resize( int w, int h ) { int tabSz = getProportions()->getTableSize() * getProportions()->getScale(); int r = tabSz / 2; agui::Point tabCenter = agui::Point( w * getProportions()->getTableOffset().getX(), h * getProportions()->getTableOffset().getY()); float widthRatio = 1.625f; int theOffset = getProportions()->isInCompactMode() ? 105 : 140; int offset = theOffset * getProportions()->getScale(); int offset2 = getProportions()->isInCompactMode() ? offset * 0.45f : offset * 0.65f; int height = solveHeight( offset,widthRatio,w - tabCenter.getX(),h - tabCenter.getY(),r ); if(height > getProportions()->getScreenHeight() * 0.31f) height = getProportions()->getScreenHeight() * 0.31f; if(Platf::isHD()) height *= 0.8; int width = height * widthRatio; agui::Point location = agui::Point( w - offset2 - width - m_chatFrame->getMargin(agui::SIDE_LEFT), h - height - offset2 - m_chatFrame->getMargin(agui::SIDE_TOP)); width += m_chatFrame->getMargin(agui::SIDE_LEFT); width += m_chatFrame->getMargin(agui::SIDE_RIGHT); height += m_chatFrame->getMargin(agui::SIDE_TOP); height += m_chatFrame->getMargin(agui::SIDE_BOTTOM); m_chatFrame->setSize(width,height); m_chatFrame->setLocation(location); changeFontSize(); m_toolbar->resize(w,h); }
void SearchResultItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { const SearchResultListModel *model = static_cast<const SearchResultListModel*>(index.model()); QBrush backBrush; bool selected = false; FileSearchResult file = getSearchResult(index); if (option.state & (QStyle::State_HasFocus | QStyle::State_Selected)) { backBrush = QColor(kFileItemBackgroundColorHighlighted); selected = true; } else { backBrush = QColor(kFileItemBackgroundColor); } // // draw item's background // painter->save(); painter->fillRect(option.rect, backBrush); painter->restore(); QIcon icon = model->data(index, Qt::DecorationRole).value<QIcon>(); // get the device pixel radio from current painter device int scale_factor = 1; #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) scale_factor = painter->device()->devicePixelRatio(); #endif // QT5 QPixmap pixmap(icon.pixmap(QSize(kFileIconWidth, kFileIconHeight) * scale_factor)); #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) if (pixmap.size() != QSize(kFileIconWidth, kFileIconHeight)) pixmap.setDevicePixelRatio(scale_factor); #endif // QT5 // // paint file icon // QPoint file_icon_pos(kMarginLeft + kPadding, kMarginTop + kPadding); file_icon_pos += option.rect.topLeft(); painter->save(); painter->drawPixmap(file_icon_pos, pixmap); painter->restore(); // Calculate the file column by the delta of mainwindow's width QString title = file.name; const int file_name_width = kFileNameWidth + seafApplet->mainWindow()->width() - seafApplet->mainWindow()->minimumWidth(); painter->save(); QPoint file_name_pos = file_icon_pos + QPoint(kFileIconWidth + kMarginBetweenFileIconAndName, -kPadding); QRect file_name_rect(file_name_pos, QSize(file_name_width, kFileNameHeight)); painter->setPen(QColor(selected ? kFileNameColorHighlighted : kFileNameColor)); painter->setFont(changeFontSize(painter->font(), kFileNameFontSize)); painter->drawText(file_name_rect, Qt::AlignLeft | Qt::AlignTop, fitTextToWidth(title, option.font, file_name_width), &file_name_rect); painter->restore(); // // Paint repo_name // int count_of_splash = file.fullpath.endsWith("/") ? 2 : 1; QString subtitle = file.fullpath.mid(1, file.fullpath.size() - count_of_splash - file.name.size()); if (!subtitle.isEmpty()) subtitle = file.repo_name + "/" + subtitle.left(subtitle.size() - 1); else subtitle = file.repo_name; painter->save(); QPoint file_desc_pos = file_name_rect.bottomLeft() + QPoint(0, kPadding / 2); QRect file_desc_rect(file_desc_pos, QSize(file_name_width, kSubtitleHeight)); painter->setFont(changeFontSize(painter->font(), kSubtitleFontSize)); painter->setPen(QColor(selected ? kSubtitleColorHighlighted : kSubtitleColor)); painter->drawText(file_desc_rect, Qt::AlignLeft | Qt::AlignTop, fitTextToWidth(subtitle, option.font, file_name_width), &file_desc_rect); painter->restore(); // // Paint file description // QString size, mtime; size = readableFileSize(file.size); mtime = translateCommitTime(file.last_modified); QString extra_title = size + " " + mtime; painter->save(); QPoint file_extra_pos = file_desc_rect.bottomLeft() + QPoint(0, kPadding / 2 + 2); QRect file_extra_rect(file_extra_pos, QSize(file_name_width, kSubtitleHeight)); painter->setFont(changeFontSize(painter->font(), kSubtitleFontSize)); painter->setPen(QColor(selected ? kSubtitleColorHighlighted : kSubtitleColor)); painter->drawText(file_extra_rect, Qt::AlignLeft | Qt::AlignTop, fitTextToWidth(extra_title, option.font, file_name_width), &file_extra_rect); painter->restore(); // // Draw the bottom border lines // painter->save(); painter->setPen(QPen(QColor(kItemBottomBorderColor), 1, Qt::SolidLine)); painter->drawLine(option.rect.bottomLeft(), option.rect.bottomRight()); painter->restore(); }
void RepoItemDelegate::paintRepoItem(QPainter *painter, const QStyleOptionViewItem& option, const RepoItem *item) const { const ServerRepo& repo = item->repo(); QBrush backBrush; bool selected = false; if (option.state & (QStyle::State_HasFocus | QStyle::State_Selected)) { backBrush = QColor(kRepoItemBackgroundColorHighlighted); selected = true; } else { backBrush = QColor(kRepoItemBackgroundColor); } painter->save(); painter->fillRect(option.rect, backBrush); painter->restore(); // Paint repo icon QPoint repo_icon_pos(kMarginLeft + kPadding, kMarginTop + kPadding); repo_icon_pos += option.rect.topLeft(); painter->save(); painter->drawPixmap(repo_icon_pos, repo.getPixmap()); painter->restore(); // Paint repo name painter->save(); QPoint repo_name_pos = repo_icon_pos + QPoint(kRepoIconWidth + kMarginBetweenRepoIconAndName, 0); QRect repo_name_rect(repo_name_pos, QSize(kRepoNameWidth, kRepoNameHeight)); painter->setPen(QColor(selected ? kRepoNameColorHighlighted : kRepoNameColor)); painter->setFont(changeFontSize(painter->font(), kRepoNameFontSize)); painter->drawText(repo_name_rect, Qt::AlignLeft | Qt::AlignTop | Qt::TextWordWrap, fitTextToWidth(repo.name, option.font, kRepoNameWidth), &repo_name_rect); // Paint repo description QPoint repo_desc_pos = repo_name_rect.bottomLeft() + QPoint(0, 5); QRect repo_desc_rect(repo_desc_pos, QSize(kRepoNameWidth, kRepoNameHeight)); painter->setFont(changeFontSize(painter->font(), kTimestampFontSize)); painter->setPen(QColor(selected ? kTimestampColorHighlighted : kTimestampColor)); QString description; const LocalRepo& r = item->localRepo(); if (r.isValid() && r.sync_state == LocalRepo::SYNC_STATE_ING) { description = r.sync_state_str; int rate, percent; if (seafApplet->rpcClient()->getRepoTransferInfo(r.id, &rate, &percent) == 0) { description += ", " + QString::number(percent) + "%"; } } else { const CloneTask& task = item->cloneTask(); if (task.isValid() && task.isDisplayable()) { if (task.error_str.length() > 0) { description = task.error_str; } else { description = task.state_str; } } else { description = translateCommitTime(repo.mtime); } } painter->drawText(repo_desc_rect, Qt::AlignLeft | Qt::AlignTop | Qt::TextWordWrap, fitTextToWidth(description, option.font, kRepoNameWidth), &repo_desc_rect); painter->restore(); // Paint repo status icon QPoint status_icon_pos = option.rect.topRight() - QPoint(40, 0); status_icon_pos.setY(option.rect.center().y() - (kRepoStatusIconHeight / 2)); QRect status_icon_rect(status_icon_pos, QSize(kRepoStatusIconWidth, kRepoStatusIconHeight)); painter->save(); painter->drawPixmap(status_icon_pos, getSyncStatusIcon(item)); painter->restore(); // Update the metrics of this item RepoItem::Metrics metrics; QPoint shift(-option.rect.topLeft().x(), -option.rect.topLeft().y()); metrics.icon_rect = QRect(repo_icon_pos, QSize(kRepoIconWidth, kRepoIconHeight)); metrics.name_rect = repo_name_rect; metrics.subtitle_rect = repo_desc_rect; metrics.status_icon_rect = status_icon_rect; metrics.icon_rect.translate(shift); metrics.name_rect.translate(shift); metrics.subtitle_rect.translate(shift); metrics.status_icon_rect.translate(shift); item->setMetrics(metrics); }
void EventItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem& option, const QModelIndex& index) const { QBrush backBrush; bool selected = false; EventItem *item = getItem(index); if (!item) { return; } const SeafEvent& event = item->event(); QString operation_text = event.op_desc; QString time_text = translateCommitTime(event.timestamp); if (option.state & (QStyle::State_HasFocus | QStyle::State_Selected)) { backBrush = QColor(kEventItemBackgroundColorHighlighted); selected = true; } else { backBrush = QColor(kEventItemBackgroundColor); } painter->save(); painter->fillRect(option.rect, backBrush); painter->restore(); painter->setRenderHint(QPainter::Antialiasing); painter->setRenderHint(QPainter::HighQualityAntialiasing); // get the device pixel radio from current painter device double scale_factor = 1; #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) scale_factor = globalDevicePixelRatio(); #endif // QT5 // paint avatar QImage avatar; if (!event.anonymous) { avatar = AvatarService::instance()->getAvatar(event.author); } QRect actualRect(0, 0, kAvatarWidth * scale_factor , kAvatarHeight * scale_factor); avatar.scaled(actualRect.size()); QImage masked_image(actualRect.size(), QImage::Format_ARGB32_Premultiplied); masked_image.fill(Qt::transparent); QPainter mask_painter; mask_painter.begin(&masked_image); mask_painter.setRenderHint(QPainter::Antialiasing); mask_painter.setRenderHint(QPainter::HighQualityAntialiasing); mask_painter.setCompositionMode(QPainter::CompositionMode_SourceOver); mask_painter.setPen(Qt::NoPen); mask_painter.setBrush(Qt::white); mask_painter.drawEllipse(actualRect); mask_painter.setCompositionMode(QPainter::CompositionMode_SourceIn); mask_painter.drawImage(actualRect, avatar); mask_painter.setCompositionMode(QPainter::CompositionMode_DestinationOver); mask_painter.fillRect(actualRect, Qt::transparent); mask_painter.end(); masked_image.setDevicePixelRatio(scale_factor); QPoint avatar_pos(kMarginLeft + kPadding, kMarginTop + kPadding); avatar_pos += option.rect.topLeft(); painter->save(); painter->drawImage(avatar_pos, masked_image); painter->restore(); auto time_font = changeFontSize(painter->font(), kTimeFontSize); auto nick_font = changeFontSize(painter->font(), kNickFontSize); auto operation_font = changeFontSize(painter->font(), kOperationFontSize); auto desc_font = changeFontSize(painter->font(), kDescriptionFontSize); auto repo_name_font = time_font; const int operation_width = ::textWidthInFont(operation_text, operation_font); const int time_width = qMin(kTimeWidth, ::textWidthInFont(time_text, time_font)); int nick_width; if (event.is_use_new_activities_api) { nick_width = option.rect.width() - kMarginLeft - kAvatarWidth - kMarginBetweenAvatarAndNick - kMarginBetweenNickAndOperation - operation_width - kMarginBetweenOperationAndTime - time_width - kPadding * 2 - kMarginRight; } else { nick_width = option.rect.width() - kMarginLeft - kAvatarWidth - kMarginBetweenAvatarAndNick - time_width - kMarginBetweenNickAndTime - kPadding * 2 - kMarginRight; } nick_width = qMin(nick_width, ::textWidthInFont(event.nick, nick_font)); // Paint nick name QPoint nick_pos = avatar_pos + QPoint(kAvatarWidth + kMarginBetweenAvatarAndNick, 0); QRect nick_rect(nick_pos, QSize(nick_width, kNickHeight)); painter->save(); painter->setPen(QColor(selected ? kNickColorHighlighted : kNickColor)); painter->setFont(nick_font); painter->drawText(nick_rect, Qt::AlignLeft | Qt::AlignTop, fitTextToWidth(event.nick, option.font, nick_width), &nick_rect); painter->restore(); // Paint operation name if (event.is_use_new_activities_api) { QPoint operation_pos = nick_pos + QPoint(nick_width + kMarginBetweenNickAndOperation, 3); QRect operation_rect(operation_pos, QSize(operation_width + 8, kOperationHeight)); painter->save(); QPainterPath path; path.addRoundedRect(operation_rect, kRadius, kRadius); painter->fillPath(path, QColor(kOperRectFillColor)); painter->setPen(QColor(kOperationColor)); painter->setFont(operation_font); painter->drawText(operation_rect, Qt::AlignCenter, fitTextToWidth(operation_text, option.font, operation_width), &operation_rect); painter->restore(); } // Paint event time painter->save(); QPoint time_pos = option.rect.topRight() + QPoint(-time_width - kPadding - kMarginRight, kMarginTop + kPadding); QRect time_rect(time_pos, QSize(time_width, kTimeHeight)); painter->setPen(QColor(selected ? kTimeColorHighlighted : kTimeColor)); painter->setFont(time_font); painter->drawText(time_rect, Qt::AlignRight | Qt::AlignTop, time_text, &time_rect); painter->restore(); // Paint description painter->save(); QString desc = event.desc; int repo_name_width = qMin(kRepoNameWidth, ::textWidthInFont(event.repo_name, repo_name_font)); int desc_width = option.rect.width() - kMarginLeft - kAvatarWidth - kMarginBetweenAvatarAndNick - kMarginBetweenRepoNameAndDesc - repo_name_width - kMarginRight - kPadding * 2; const int desc_height = ::textHeightInFont(desc, desc_font) * 2; // const QPoint event_desc_pos = option.rect.bottomLeft() + QPoint(nick_rect.left(), - desc_height - kExtraPadding - kMarginBottom); const QPoint event_desc_pos = nick_rect.bottomLeft() + QPoint(0, kVerticalMarginBetweenNickAndDesc); QRect event_desc_rect(event_desc_pos, QSize(desc_width, desc_height)); painter->setFont(desc_font); painter->setPen(QColor(selected ? kDescriptionColorHighlighted : kDescriptionColor)); desc.replace(QChar('\n'), QChar(' ')); painter->drawText(event_desc_rect, Qt::AlignLeft | Qt::AlignTop | Qt::TextWrapAnywhere, // we have two lines fitTextToWidth(desc, desc_font, desc_width * 2), &event_desc_rect); painter->restore(); // Paint repo name painter->save(); repo_name_width += desc_width - event_desc_rect.width(); // if (index.row() == 1) { // printf ("width diff = %d\n", desc_width - event_desc_rect.width()); // } const int repo_name_height = ::textHeightInFont(event.repo_name, repo_name_font); const QPoint event_repo_name_pos = option.rect.bottomRight() + QPoint(-repo_name_width - kPadding - kMarginRight, -repo_name_height - kExtraPadding - kMarginBottom); QRect event_repo_name_rect(event_repo_name_pos, QSize(repo_name_width, kNickHeight)); painter->setFont(repo_name_font); painter->setPen(QColor(selected ? kRepoNameColorHighlighted : kRepoNameColor)); painter->drawText( event_repo_name_rect, Qt::AlignRight | Qt::AlignTop | Qt::TextSingleLine, fitTextToWidth(event.repo_name, repo_name_font, repo_name_width), &event_repo_name_rect); painter->restore(); // const EventsListModel *model = (const EventsListModel*)index.model(); // // Draw the bottom border lines except for the last item (if the "load more" is present") // We minus 2 here becase: // 1) the row index starts from 0 // 2) we addded a row for the "load more" data in the end // if (model->loadMoreIndex().isValid() && index.row() == model->rowCount() - 2) { // return; // } painter->save(); painter->setPen(QPen(QColor(kItemBottomBorderColor), 1, Qt::SolidLine)); QPoint left = option.rect.bottomLeft(); left.setY(left.y() + 1); QPoint right = option.rect.bottomRight(); right.setY(right.y() + 1); painter->drawLine(left, right); painter->restore(); }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { EdamProtocol *edam = EdamProtocol::GetInstance(); ui->setupUi(this); pdfCache * pdf = new pdfCache(this); CustomNetworkAccessManager *nm = new CustomNetworkAccessManager(ui->editor->page()->networkAccessManager(), this, pdf); edam->setCNAM(nm); ui->editor->page()->setNetworkAccessManager(nm); Speller::setSettings(new DBSpellSettings(this, ui->editor)); ui->editor->setContextMenuPolicy(Qt::CustomContextMenu); ui->editor->load(QUrl("qrc:///html/noteajax.html")); jsB = new jsBridge(this, pdf); jsB->setWebView(ui->editor); enmlWritter = new enml2(this); connect(ui->editor->page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(addJSObject())); loaded = false; editingEnabled = false; tagsActions = new QActionGroup(this); newTag = new TagLabel(this); newTag->hide(); ui->tagsBar->addWidget(newTag); appIcon = QIcon(":img/hippo64.png"); trayIcon = NULL; bool sysTrayEnabled = sql::readSyncStatus("systemTray", true).toBool(); if (QSystemTrayIcon::isSystemTrayAvailable() && sysTrayEnabled) enableSystemTrayIcon(true); connect(edam, SIGNAL(AuthenticateFailed()), this, SLOT(authentificationFailed())); connect(edam, SIGNAL(syncFinished()), this, SLOT(syncFinished())); connect(edam, SIGNAL(syncStarted(int)), this, SLOT(syncStarted(int))); connect(edam, SIGNAL(noteGuidChanged(QString,QString)), this, SLOT(changeNoteGuid(QString,QString))); connect(ui->notebooks, SIGNAL(itemSelectionChanged()), this, SLOT(switchNotebook())); connect(ui->tags, SIGNAL(itemSelectionChanged()), this, SLOT(switchTag())); connect(ui->tags, SIGNAL(tagAdded(QString,QString)), this, SLOT(addTag(QString,QString))); connect(ui->tags, SIGNAL(tagsUpdated()), this, SLOT(updateTagsToolBar())); connect(ui->tags, SIGNAL(tagsUpdated()), this, SLOT(switchTag())); connect(ui->NotesList, SIGNAL(noteSwitched()), this, SLOT(switchNote())); connect(ui->action_Abaut, SIGNAL(triggered()), this, SLOT(loadAboutInfo())); connect(ui->actionClose, SIGNAL(triggered()), this, SLOT(closeWindow())); connect(ui->actionNew_Note, SIGNAL(triggered()), this, SLOT(newNote())); connect(ui->actionSync, SIGNAL(triggered()), this, SLOT(sync())); connect(ui->noteTitle, SIGNAL(textEdited(QString)), this, SLOT(noteTitleChange(QString))); connect(ui->actionAccount_info, SIGNAL(triggered()), this, SLOT(showUserInfo())); connect(ui->editor->page(), SIGNAL(linkClicked(QUrl)), this, SLOT(openURL(QUrl))); connect(ui->editor->page(), SIGNAL(microFocusChanged()), this, SLOT(updateEditButtonsState())); connect(ui->editor, SIGNAL(selectionChanged()), this, SLOT(updateSelectionButtonsState())); connect(ui->editor->page(), SIGNAL(downloadRequested(QNetworkRequest)), this, SLOT(downloadRequested(QNetworkRequest))); connect(ui->editor, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(editorContextMenuRequested(QPoint))); connect(ui->editor, SIGNAL(fileInserted(QString)), this, SLOT(insertFile(QString))); connect(ui->notebooks, SIGNAL(noteMoved(QString,QString)), this, SLOT(moveNote(QString,QString))); connect(ui->notebooks, SIGNAL(noteDeleted(QString)), this, SLOT(deleteNote(QString))); connect(ui->notebooks, SIGNAL(noteRestored(QString,QString)), this, SLOT(restoreNote(QString,QString))); connect(ui->NotesList, SIGNAL(noteDeleted(QString)), this, SLOT(deleteNote(QString))); connect(ui->NotesList, SIGNAL(noteRestored(QString)), this, SLOT(restoreNote(QString))); connect(ui->NotesList, SIGNAL(noteCreated()), this, SLOT(newNote())); connect(ui->NotesList, SIGNAL(reloaded()), this, SLOT(updateCurrentNoteName())); connect(ui->editButton, SIGNAL(toggled(bool)), this, SLOT(setEditable(bool))); connect(ui->actionDelete_Note, SIGNAL(triggered()), this, SLOT(deleteNote())); connect(ui->toolBox, SIGNAL(currentChanged(int)), this, SLOT(changeTab(int))); connect(ui->editor->page(), SIGNAL(linkHovered(QString,QString,QString)), this, SLOT(linkHovered(QString,QString,QString))); connect(jsB, SIGNAL(hintMessage(QString,int)), ui->statusbar, SLOT(showMessage(QString,int))); connect(jsB, SIGNAL(noteChanged(QString)), this, SLOT(updateTagsToolBar(QString))); connect(jsB, SIGNAL(activeNoteSelectionChanged(bool)), ui->actionDelete_Note, SLOT(setEnabled(bool))); connect(jsB, SIGNAL(activeNoteSelectionChanged(bool)), ui->editButton, SLOT(setEnabled(bool))); connect(jsB, SIGNAL(editingStarted(bool)), ui->editButton, SLOT(setChecked(bool))); connect(jsB, SIGNAL(titleUpdated(QString,QString)), this, SLOT(updateNoteTitle(QString,QString))); connect(jsB, SIGNAL(conflictAdded(qint64,QString,bool)), this, SLOT(addConflict(qint64,QString,bool))); connect(jsB, SIGNAL(noteSelectionChanged(bool)), ui->actionNote_Info, SLOT(setEnabled(bool))); connect(jsB, SIGNAL(noteSelectionChanged(bool)), ui->actionExport, SLOT(setEnabled(bool))); connect(jsB, SIGNAL(noteSelectionChanged(bool)), ui->actionPrint, SLOT(setEnabled(bool))); connect(ui->editor, SIGNAL(tagUpdated(QString,bool)), this, SLOT(updateTag(QString,bool))); connect(tagsActions, SIGNAL(triggered(QAction*)), this, SLOT(tagClicked(QAction*))); connect(newTag, SIGNAL(tagCreated(QString)), this, SLOT(createTag(QString))); connect(ui->actionKeep_only_this_Version, SIGNAL(triggered()), this, SLOT(keepThisVersion())); connect(ui->actionNote_Info, SIGNAL(triggered()), this, SLOT(showNoteInfo())); connect(ui->actionExport, SIGNAL(triggered()), this, SLOT(exportNote())); connect(ui->actionPrint, SIGNAL(triggered()), this, SLOT(print())); connect(this, SIGNAL(titleChanged(QString,QString)), jsB, SIGNAL(titleChanged(QString,QString))); setWindowIcon(appIcon); setWindowTitle("Hippo Notes"); setTabOrder(ui->noteTitle, ui->editor); ui->notebooks->setSortingEnabled(true); ui->notebooks->sortByColumn(0, Qt::AscendingOrder); ui->editBar->setVisible(false); ui->mainToolBar->addAction(ui->actionNew_Note); ui->mainToolBar->addAction(ui->actionSync); QFontComboBox *font = new QFontComboBox(this); font->setDisabled(true); font->setFontFilters(QFontComboBox::ScalableFonts); font->setEditable(false); connect(this, SIGNAL(editButtonsStateChanged(bool)), font, SLOT(setEnabled(bool))); connect(this, SIGNAL(updateFont(QFont)), font, SLOT(setCurrentFont(QFont))); connect(font, SIGNAL(activated(QString)), this, SLOT(changeFont(QString))); ui->editBar->addWidget(font); QComboBox *fontSize = new QComboBox(this); fontSize->setDisabled(true); fontSize->setEditable(false); for (int i = 1; i <= 7; i++) fontSize->addItem(QString::number(i)); connect(this, SIGNAL(editButtonsStateChanged(bool)), fontSize, SLOT(setEnabled(bool))); connect(this, SIGNAL(updateFontSize(int)), fontSize, SLOT(setCurrentIndex(int))); connect(fontSize, SIGNAL(activated(QString)), this, SLOT(changeFontSize(QString))); ui->editBar->addWidget(fontSize); QAction *boldIco = ui->editor->pageAction(QWebPage::ToggleBold); boldIco->setIcon(QIcon::fromTheme("format-text-bold")); ui->editBar->addAction(boldIco); QAction *italicIco = ui->editor->pageAction(QWebPage::ToggleItalic); italicIco->setIcon(QIcon::fromTheme("format-text-italic")); ui->editBar->addAction(italicIco); QAction *underlineIco = ui->editor->pageAction(QWebPage::ToggleUnderline); underlineIco->setIcon(QIcon::fromTheme("format-text-underline")); ui->editBar->addAction(underlineIco); QAction *strikethroughIco = ui->editor->pageAction(QWebPage::ToggleStrikethrough); strikethroughIco->setIcon(QIcon::fromTheme("format-text-strikethrough")); ui->editBar->addAction(strikethroughIco); ui->editBar->addSeparator(); QAction *undoIco = ui->editor->pageAction(QWebPage::Undo); undoIco->setIcon(QIcon::fromTheme("edit-undo")); undoIco->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Z)); ui->editBar->addAction(undoIco); ui->menu_Edit->addAction(undoIco); QAction *redoIco = ui->editor->pageAction(QWebPage::Redo); redoIco->setIcon(QIcon::fromTheme("edit-redo")); redoIco->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_Z)); ui->editBar->addAction(redoIco); ui->menu_Edit->addAction(redoIco); ui->editBar->addSeparator(); QAction *rformatIco = ui->editor->pageAction(QWebPage::RemoveFormat); rformatIco->setIcon(QIcon::fromTheme("edit-clear")); ui->editBar->addAction(rformatIco); ui->editBar->addSeparator(); QAction *leftIco = ui->editor->pageAction(QWebPage::AlignLeft); leftIco->setIcon(QIcon::fromTheme("format-justify-left")); ui->editBar->addAction(leftIco); QAction *centerIco = ui->editor->pageAction(QWebPage::AlignCenter); centerIco->setIcon(QIcon::fromTheme("format-justify-center")); ui->editBar->addAction(centerIco); QAction *rightIco = ui->editor->pageAction(QWebPage::AlignRight); rightIco->setIcon(QIcon::fromTheme("format-justify-right")); ui->editBar->addAction(rightIco); QAction *fillIco = ui->editor->pageAction(QWebPage::AlignJustified); fillIco->setIcon(QIcon::fromTheme("format-justify-fill")); ui->editBar->addAction(fillIco); ui->editBar->addSeparator(); QAction *indentIco = ui->editor->pageAction(QWebPage::Indent); indentIco->setIcon(QIcon::fromTheme("format-indent-more")); ui->editBar->addAction(indentIco); QAction *outdentIco = ui->editor->pageAction(QWebPage::Outdent); outdentIco->setIcon(QIcon::fromTheme("format-indent-less")); ui->editBar->addAction(outdentIco); QAction *superscriptIco = ui->editor->pageAction(QWebPage::ToggleSuperscript); superscriptIco->setIcon(QIcon::fromTheme("format-text-superscript")); ui->editBar->addAction(superscriptIco); QAction *subscriptIco = ui->editor->pageAction(QWebPage::ToggleSubscript); subscriptIco->setIcon(QIcon::fromTheme("format-text-subscript")); ui->editBar->addAction(subscriptIco); QAction *unorderedIco = ui->editor->pageAction(QWebPage::InsertUnorderedList); unorderedIco->setIcon(QIcon::fromTheme("format-list-unordered")); ui->editBar->addAction(unorderedIco); QAction *orderedIco = ui->editor->pageAction(QWebPage::InsertOrderedList); orderedIco->setIcon(QIcon::fromTheme("format-list-ordered")); ui->editBar->addAction(orderedIco); QAction *lineIco = new QAction("Insert horizontal line", this); lineIco->setIcon(QIcon::fromTheme("insert-horizontal-rule")); lineIco->setDisabled(true); connect(this, SIGNAL(editButtonsStateChanged(bool)), lineIco, SLOT(setEnabled(bool))); connect(lineIco, SIGNAL(triggered()), this, SLOT(insertHorizontalLine())); ui->editBar->addAction(lineIco); ui->menu_Edit->addSeparator(); QAction *cutIco = ui->editor->pageAction(QWebPage::Cut); cutIco->setIcon(QIcon::fromTheme("edit-cut")); cutIco->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_X)); ui->menu_Edit->addAction(cutIco); QAction *copyIco = ui->editor->pageAction(QWebPage::Copy); copyIco->setIcon(QIcon::fromTheme("edit-copy")); copyIco->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_C)); ui->menu_Edit->addAction(copyIco); QAction *pasteIco = ui->editor->pageAction(QWebPage::Paste); pasteIco->setIcon(QIcon::fromTheme("edit-paste")); pasteIco->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_V)); ui->menu_Edit->addAction(pasteIco); QAction *pasteSpecialIco = ui->editor->pageAction(QWebPage::PasteAndMatchStyle); pasteSpecialIco->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_V)); ui->menu_Edit->addAction(pasteSpecialIco); ui->menu_Edit->addSeparator(); QAction *insertUrlIco = new QAction("Create link", this); insertUrlIco->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_L)); insertUrlIco->setDisabled(true); insertUrlIco->setIcon(QIcon::fromTheme("insert-link")); connect(this, SIGNAL(selectionButtonsStateChanged(bool)), insertUrlIco, SLOT(setDisabled(bool))); connect(insertUrlIco, SIGNAL(triggered()), this, SLOT(insertUrl())); ui->menu_Edit->addAction(insertUrlIco); QAction *todoIco = new QAction("Insert To-do Checkbox", this); todoIco->setIcon(QIcon::fromTheme("checkbox")); todoIco->setDisabled(true); connect(this, SIGNAL(editButtonsStateChanged(bool)), todoIco, SLOT(setEnabled(bool))); connect(todoIco, SIGNAL(triggered()), jsB, SIGNAL(insertToDo())); ui->menu_Edit->addAction(todoIco); QAction *insertImage = new QAction("Insert Image", this); insertImage->setIcon(QIcon::fromTheme("insert-image")); insertImage->setDisabled(true); connect(this, SIGNAL(editButtonsStateChanged(bool)), insertImage, SLOT(setEnabled(bool))); connect(insertImage, SIGNAL(triggered()), this, SLOT(insertImg())); ui->menu_Edit->addAction(insertImage); QAction *insertFile = new QAction("Insert File", this); insertFile->setDisabled(true); connect(this, SIGNAL(editButtonsStateChanged(bool)), insertFile, SLOT(setEnabled(bool))); connect(insertFile, SIGNAL(triggered()), this, SLOT(insertFile())); ui->menu_Edit->addAction(insertFile); QAction *encryptIco = new QAction("Encrypt Selected Text...", this); encryptIco->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_X)); encryptIco->setDisabled(true); encryptIco->setIcon(QIcon::fromTheme("document-edit-encrypt")); connect(this, SIGNAL(selectionButtonsStateChanged(bool)), encryptIco, SLOT(setDisabled(bool))); connect(encryptIco, SIGNAL(triggered()), jsB, SIGNAL(encryptText())); ui->menu_Edit->addAction(encryptIco); ui->menu_Edit->addSeparator(); QAction *options = new QAction("&Options...", this); options->setIcon(QIcon::fromTheme("preferences-other")); connect(options, SIGNAL(triggered()), this, SLOT(showOptions())); ui->menu_Edit->addAction(options); clearConflictBar(); connect(jsB, SIGNAL(showConflict()), ui->conflictBar, SLOT(show())); connect(jsB, SIGNAL(showConflict()), ui->conflictBarBottom, SLOT(show())); conflictsGroup = new QActionGroup(this); connect(conflictsGroup, SIGNAL(triggered(QAction*)), this, SLOT(changeNoteVersion(QAction*))); searchIndex = new SearchIndex(this); connect(ui->searchButton, SIGNAL(clicked()), this, SLOT(search())); connect(edam, SIGNAL(syncFinished()), searchIndex, SLOT(buildSearchIndex())); connect(jsB, SIGNAL(noteUpdated(QString)), searchIndex, SLOT(updateNoteIndex(QString))); connect(edam, SIGNAL(noteUpdated(QString)), searchIndex, SLOT(dropNoteIndex(QString))); connect(ui->searchInput, SIGNAL(returnPressed()), this, SLOT(search())); QByteArray mainWindowGeometry = sql::readSyncStatus("mainWindowGeometry").toString().toLatin1(); if (!mainWindowGeometry.isEmpty()) restoreGeometry(QByteArray::fromBase64(mainWindowGeometry)); QByteArray mainWidgetsSplitterState = sql::readSyncStatus("mainWidgetsSplitterState").toString().toLatin1(); if (!mainWidgetsSplitterState.isEmpty()) ui->mainWidgetsSplitter->restoreState(QByteArray::fromBase64(mainWidgetsSplitterState)); //showWindow(); edam->init(); }
void Menu::handleEvents(SDL_Event* event) { while(SDL_PollEvent(event)) { if (event->type == SDL_QUIT) { if (m_menuState == MAIN_MENU) { Application::getInstance().setAppState(APP_EXITING); } if (m_menuState == OPTIONS_MENU) { m_menuState = MAIN_MENU; m_optionsButtons[7]->setClick(false); } } } if (m_menuState == MAIN_MENU) { for (Button* button : m_buttons) button->handleEvents(event, m_cursor->getCollisionBox()); //Play Game if (m_buttons[0]->isClicked()) { g_gameState = new SelectionState(false); g_showCollisionBox = false; } //Options State if (m_buttons[1]->isClicked()) { m_menuState = OPTIONS_MENU; } //Exit Game if (m_buttons[2]->isClicked()) { Application::getInstance().setAppState(APP_EXITING); } //Editor State if (m_buttons[3]->isClicked()) { g_gameState = new SelectionState(true); g_showCollisionBox = true; } } else if (m_menuState == OPTIONS_MENU) { for (Button* button : m_optionsButtons) button->handleEvents(event, m_cursor->getCollisionBox()); changeFontSize(64); //Bgm decrement if (m_optionsButtons[1]->isClicked()) { g_bgmVolume -= 5; if (g_bgmVolume < 0) g_bgmVolume = 0; Mix_VolumeMusic((int)(MIX_MAX_VOLUME * (g_bgmVolume / 100.f))); delete m_optionsButtons[0]; m_optionsButtons[0] = new Button(Vector2f(SCREEN_WIDTH * 0.50, SCREEN_HEIGHT / 2), SCREEN_WIDTH / 4, SCREEN_HEIGHT / 7, "Music: " + std::to_string(g_bgmVolume) + "%", false); } //Bgm Increment if (m_optionsButtons[2]->isClicked()) { g_bgmVolume += 5; if (g_bgmVolume > 100) g_bgmVolume = 100; Mix_VolumeMusic((int)(MIX_MAX_VOLUME * (g_bgmVolume / 100.f))); delete m_optionsButtons[0]; m_optionsButtons[0] = new Button(Vector2f(SCREEN_WIDTH * 0.50, SCREEN_HEIGHT / 2), SCREEN_WIDTH / 4, SCREEN_HEIGHT / 7, "Music: " + std::to_string(g_bgmVolume) + "%", false); } //Sfx decrement if (m_optionsButtons[4]->isClicked()) { g_sfxVolume -= 5; if (g_sfxVolume < 0) g_sfxVolume = 0; delete m_optionsButtons[3]; m_optionsButtons[3] = new Button(Vector2f(SCREEN_WIDTH * 0.50, SCREEN_HEIGHT - (SCREEN_HEIGHT / 3)), SCREEN_WIDTH / 4, SCREEN_HEIGHT / 7, "Sound: " + std::to_string(g_sfxVolume) + "%", false); } //Sfx Increment if (m_optionsButtons[5]->isClicked()) { g_sfxVolume += 5; if (g_sfxVolume > 100) g_sfxVolume = 100; delete m_optionsButtons[3]; m_optionsButtons[3] = new Button(Vector2f(SCREEN_WIDTH * 0.50, SCREEN_HEIGHT - (SCREEN_HEIGHT / 3)), SCREEN_WIDTH / 4, SCREEN_HEIGHT / 7, "Sound: " + std::to_string(g_sfxVolume) + "%", false); } //Reset Save if (m_optionsButtons[6]->isClicked()) { } //Home if (m_optionsButtons[7]->isClicked()) { m_menuState = MAIN_MENU; } //Credits if (m_optionsButtons[8]->isClicked()) { g_gameState = new Credits(); } changeFontSize(16); if (event->type == SDL_KEYDOWN) { if (event->key.keysym.sym == SDLK_ESCAPE) m_menuState = MAIN_MENU; } } m_cursor->handleEvents(event); }
void EventItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem& option, const QModelIndex& index) const { QBrush backBrush; bool selected = false; EventItem *item = getItem(index); const SeafEvent& event = item->event(); QString time_text = translateCommitTime(event.timestamp); if (option.state & (QStyle::State_HasFocus | QStyle::State_Selected)) { backBrush = QColor(kEventItemBackgroundColorHighlighted); selected = true; } else { backBrush = QColor(kEventItemBackgroundColor); } painter->save(); painter->fillRect(option.rect, backBrush); painter->restore(); painter->setRenderHint(QPainter::Antialiasing); painter->setRenderHint(QPainter::HighQualityAntialiasing); // get the device pixel radio from current painter device int scale_factor = 1; #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) scale_factor = painter->device()->devicePixelRatio(); #endif // QT5 // paint avatar QImage avatar; if (!event.anonymous) { avatar = AvatarService::instance()->getAvatar(event.author); } QRect actualRect(0, 0, kAvatarWidth * scale_factor , kAvatarHeight * scale_factor); avatar.scaled(actualRect.size()); QImage masked_image(actualRect.size(), QImage::Format_ARGB32_Premultiplied); masked_image.fill(Qt::transparent); QPainter mask_painter; mask_painter.begin(&masked_image); mask_painter.setRenderHint(QPainter::Antialiasing); mask_painter.setRenderHint(QPainter::HighQualityAntialiasing); mask_painter.setCompositionMode(QPainter::CompositionMode_SourceOver); mask_painter.setPen(Qt::NoPen); mask_painter.setBrush(Qt::white); mask_painter.drawEllipse(actualRect); mask_painter.setCompositionMode(QPainter::CompositionMode_SourceIn); mask_painter.drawImage(actualRect, avatar); mask_painter.setCompositionMode(QPainter::CompositionMode_DestinationOver); mask_painter.fillRect(actualRect, Qt::transparent); mask_painter.end(); #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) masked_image.setDevicePixelRatio(scale_factor); #endif // QT5 QPoint avatar_pos(kMarginLeft + kPadding, kMarginTop + kPadding); avatar_pos += option.rect.topLeft(); painter->save(); painter->drawImage(avatar_pos, masked_image); painter->restore(); const int time_width = qMin(kTimeWidth, ::textWidthInFont(time_text, changeFontSize(painter->font(), kTimeFontSize))); int nick_width = option.rect.width() - kMarginLeft - kAvatarWidth - kMarginBetweenAvatarAndNick - time_width - kMarginBetweenNickAndTime - kPadding * 2 - kMarginRight; nick_width = qMin(nick_width, ::textWidthInFont(event.nick, changeFontSize(painter->font(), kNickFontSize))); // Paint nick name QPoint nick_pos = avatar_pos + QPoint(kAvatarWidth + kMarginBetweenAvatarAndNick, 0); QRect nick_rect(nick_pos, QSize(nick_width, kNickHeight)); painter->save(); painter->setPen(QColor(selected ? kNickColorHighlighted : kNickColor)); painter->setFont(changeFontSize(painter->font(), kNickFontSize)); painter->drawText(nick_rect, Qt::AlignLeft | Qt::AlignTop, fitTextToWidth(event.nick, option.font, nick_width), &nick_rect); painter->restore(); // Paint event time painter->save(); QPoint time_pos = option.rect.topRight() + QPoint(-time_width - kPadding - kMarginRight, kMarginTop + kPadding); QRect time_rect(time_pos, QSize(time_width, kTimeHeight)); painter->setPen(QColor(selected ? kTimeColorHighlighted : kTimeColor)); painter->setFont(changeFontSize(painter->font(), kTimeFontSize)); painter->drawText(time_rect, Qt::AlignRight | Qt::AlignTop, time_text, &time_rect); painter->restore(); // Paint description painter->save(); const int repo_name_width = qMin(kRepoNameWidth, ::textWidthInFont(event.repo_name, changeFontSize(painter->font(), kTimeFontSize))); const int repo_name_height = ::textHeightInFont(event.repo_name, changeFontSize(painter->font(), kTimeFontSize)); int desc_width = option.rect.width() - kMarginLeft - kAvatarWidth - kMarginBetweenAvatarAndNick - kPadding * 3 - kMarginBetweenRepoNameAndDesc - repo_name_width - kMarginRight; desc_width = qMin(desc_width, ::textWidthInFont(event.desc, changeFontSize(painter->font(), kDescriptionFontSize))); const int desc_height = ::textHeightInFont(event.desc, changeFontSize(painter->font(), kDescriptionFontSize)) * 2; const QPoint event_desc_pos = option.rect.bottomLeft() + QPoint(nick_rect.left(), - desc_height - kExtraPadding - kMarginBottom); QRect event_desc_rect(event_desc_pos, QSize(desc_width, desc_height)); painter->setFont(changeFontSize(painter->font(), kDescriptionFontSize)); painter->setPen(QColor(selected ? kDescriptionColorHighlighted : kDescriptionColor)); QString desc = event.desc; desc.replace(QChar('\n'), QChar(' ')); painter->drawText(event_desc_rect, Qt::AlignLeft | Qt::AlignTop | Qt::TextWrapAnywhere, // we have two lines fitTextToWidth(desc, option.font, desc_width * 2), &event_desc_rect); painter->restore(); // Paint repo name painter->save(); const QPoint event_repo_name_pos = option.rect.bottomRight() + QPoint(-repo_name_width - kPadding - kMarginRight, -repo_name_height - kExtraPadding - kMarginBottom); QRect event_repo_name_rect(event_repo_name_pos, QSize(repo_name_width, kNickHeight)); painter->setFont(changeFontSize(painter->font(), kTimeFontSize)); painter->setPen(QColor(selected ? kRepoNameColorHighlighted : kRepoNameColor)); painter->drawText(event_repo_name_rect, Qt::AlignRight | Qt::AlignTop | Qt::TextSingleLine, fitTextToWidth(event.repo_name, option.font, repo_name_width), &event_repo_name_rect); painter->restore(); // Draw the bottom border lines painter->save(); painter->setPen(QPen(QColor(kItemBottomBorderColor), 1, Qt::SolidLine)); painter->drawLine(option.rect.bottomLeft(), option.rect.bottomRight()); painter->restore(); }