Skip to content

Commit

Permalink
Go to Emojipedia page with context menu
Browse files Browse the repository at this point in the history
This patch makes it possible for the user to right-click an emoji,
bringing up a context menu, and then click the "Go to Emojipedia page"
action to perform the same action as when pressing F12 with a selected
emoji.

Because this is not configurable, I'm removing the emojiInfoRequested()
signal to embed the URL opening action directly into the main window.
jome::gotoEmojipediaPage(), declared in `jome/emojipedia.hpp`, does this
job.

Signed-off-by: Philippe Proulx <[email protected]>
  • Loading branch information
eepp committed Dec 7, 2021
1 parent 962e4f0 commit 377c8b4
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 18 deletions.
3 changes: 3 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ To cancel, 👇 **Escape** or close the window.
To go to the https://emojipedia.org/[Emojipedia] 📃 of the
<<select,selected>> emoji, 👇 **F12**.

To go to the Emojipedia 📃 of any emoji with the 🖱, right-click it and
click "`Go to Emojipedia page`".

[[cl-options]]
=== Command-line options

Expand Down
1 change: 1 addition & 0 deletions jome/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ add_executable (
emoji-db.cpp
tinyutf8.cpp
settings.cpp
emojipedia.cpp
)
target_link_libraries (
jome
Expand Down
24 changes: 24 additions & 0 deletions jome/emojipedia.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright (C) 2021 Philippe Proulx <eepp.ca>
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/

#include <QDesktopServices>
#include <QString>
#include <QUrl>

#include "emojipedia.hpp"
#include "emoji-db.hpp"

namespace jome {

void gotoEmojipediaPage(const Emoji& emoji)
{
QDesktopServices::openUrl(QUrl {
QString {"https://emojipedia.org/"} + QString::fromStdString(emoji.str())
});
}

} // namespace jome
19 changes: 19 additions & 0 deletions jome/emojipedia.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright (C) 2021 Philippe Proulx <eepp.ca>
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/

#ifndef _JOME_EMOJIPEDIA_HPP
#define _JOME_EMOJIPEDIA_HPP

#include "emoji-db.hpp"

namespace jome {

void gotoEmojipediaPage(const Emoji& emoji);

} // namespace jome

#endif // _JOME_EMOJIPEDIA_HPP
8 changes: 0 additions & 8 deletions jome/jome.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@

#include <QApplication>
#include <QCommandLineParser>
#include <QDesktopServices>
#include <QString>
#include <QProcess>
#include <QTimer>
#include <QUrl>
#include <iostream>
#include <cstdio>
#include <cstdlib>
Expand Down Expand Up @@ -279,12 +277,6 @@ int main(int argc, char **argv)
QTimer::singleShot(0, &win, &jome::QJomeWindow::emojiDbChanged);
}
});
QObject::connect(&win, &jome::QJomeWindow::emojiInfoRequested,
[&](const auto& emoji) {
QDesktopServices::openUrl(QUrl {
QString {"https://emojipedia.org/"} + QString::fromStdString(emoji.str())
});
});

if (params.serverName) {
server = std::make_unique<jome::QJomeServer>(nullptr, *params.serverName);
Expand Down
14 changes: 13 additions & 1 deletion jome/q-emoji-graphics-item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
*/

#include <QGraphicsSceneMouseEvent>
#include <cstdio>
#include <QMenu>

#include "q-emoji-graphics-item.hpp"
#include "q-emojis-widget.hpp"
#include "emojipedia.hpp"

namespace jome {

Expand Down Expand Up @@ -46,4 +47,15 @@ void QEmojiGraphicsItem::hoverLeaveEvent(QGraphicsSceneHoverEvent * const event)
QGraphicsPixmapItem::hoverLeaveEvent(event);
}

void QEmojiGraphicsItem::contextMenuEvent(QGraphicsSceneContextMenuEvent * const event)
{
QMenu menu;
const auto requestEmojiInfoAction = menu.addAction("Go to Emojipedia page");
const auto selAction = menu.exec(event->screenPos());

if (selAction == requestEmojiInfoAction) {
gotoEmojipediaPage(*_emoji);
}
}

} // namespace jome
1 change: 1 addition & 0 deletions jome/q-emoji-graphics-item.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class QEmojiGraphicsItem :
void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override;
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override;
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override;

private:
const Emoji * const _emoji;
Expand Down
20 changes: 13 additions & 7 deletions jome/q-jome-window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include "q-jome-window.hpp"
#include "q-cat-list-widget-item.hpp"
#include "emojipedia.hpp"

namespace jome {

Expand Down Expand Up @@ -435,13 +436,6 @@ void QJomeWindow::_acceptSelectedEmoji(const boost::optional<Emoji::SkinTone>& s
}
}

void QJomeWindow::_requestSelectedEmojiInfo()
{
if (_selectedEmoji) {
emit this->emojiInfoRequested(*_selectedEmoji);
}
}

void QJomeWindow::_acceptEmoji(const Emoji& emoji,
const boost::optional<Emoji::SkinTone>& skinTone)
{
Expand All @@ -452,6 +446,18 @@ void QJomeWindow::_acceptEmoji(const Emoji& emoji,
emit this->emojiChosen(emoji, skinTone);
}

void QJomeWindow::_requestSelectedEmojiInfo()
{
if (_selectedEmoji) {
this->_requestEmojiInfo(*_selectedEmoji);
}
}

void QJomeWindow::_requestEmojiInfo(const Emoji& emoji)
{
gotoEmojipediaPage(emoji);
}

void QJomeWindow::_updateInfoLabel(const Emoji * const emoji)
{
QString text;
Expand Down
4 changes: 2 additions & 2 deletions jome/q-jome-window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ class QJomeWindow :

signals:
void emojiChosen(const Emoji& emoji, const boost::optional<Emoji::SkinTone>& skinTone);
void emojiInfoRequested(const Emoji& emoji);
void canceled();

public slots:
Expand All @@ -82,8 +81,9 @@ public slots:
void _updateInfoLabel(const Emoji *emoji);
void _findEmojis(const std::string& cat, const std::string& needles);
void _acceptSelectedEmoji(const boost::optional<Emoji::SkinTone>& skinTone);
void _requestSelectedEmojiInfo();
void _acceptEmoji(const Emoji& emoji, const boost::optional<Emoji::SkinTone>& skinTone);
void _requestSelectedEmojiInfo();
void _requestEmojiInfo(const Emoji& emoji);

private slots:
void _searchTextChanged(const QString& text);
Expand Down

0 comments on commit 377c8b4

Please sign in to comment.