diff --git a/src/adapters/controllers/dictionary_controller.cpp b/src/adapters/controllers/dictionary_controller.cpp
index f4bfefdd3..0b6cc43a1 100644
--- a/src/adapters/controllers/dictionary_controller.cpp
+++ b/src/adapters/controllers/dictionary_controller.cpp
@@ -64,7 +64,7 @@ void DictionaryController::processDefinition(bool success,
// with an uppercase letter after a period, but the dictionary API is
// case-sensitive so we change it to lowercase by default. This can
// cause problems for names or different languages though.
- if(!m_searchedForWord[0].isUpper())
+ if(!m_searchedForWord.isEmpty() && !m_searchedForWord[0].isUpper())
{
auto capitalizedWord =
m_searchedForWord[0].toUpper() + m_searchedForWord.mid(1);
diff --git a/src/presentation/modules/CppElements/page_view.cpp b/src/presentation/modules/CppElements/page_view.cpp
index 1509a3226..e693e4e7b 100644
--- a/src/presentation/modules/CppElements/page_view.cpp
+++ b/src/presentation/modules/CppElements/page_view.cpp
@@ -280,6 +280,11 @@ void PageView::keyPressEvent(QKeyEvent* event)
}
}
+void PageView::hoverLeaveEvent(QHoverEvent* event)
+{
+ resetCursorToDefault();
+}
+
void PageView::paintSelectionOnPage(QPainter& painter)
{
auto& selectionRects = m_pageController->getBufferedSelectionRects();
diff --git a/src/presentation/modules/CppElements/page_view.hpp b/src/presentation/modules/CppElements/page_view.hpp
index 279ebd1fd..553726ed9 100644
--- a/src/presentation/modules/CppElements/page_view.hpp
+++ b/src/presentation/modules/CppElements/page_view.hpp
@@ -72,6 +72,7 @@ private slots:
virtual void mouseMoveEvent(QMouseEvent* event) override;
virtual void hoverMoveEvent(QHoverEvent* event) override;
virtual void keyPressEvent(QKeyEvent* event) override;
+ virtual void hoverLeaveEvent(QHoverEvent* event) override;
private:
void selectSingleWord();
diff --git a/src/presentation/readingPage/MDictionaryPopup.qml b/src/presentation/readingPage/MDictionaryPopup.qml
index dbd7307ee..267075944 100644
--- a/src/presentation/readingPage/MDictionaryPopup.qml
+++ b/src/presentation/readingPage/MDictionaryPopup.qml
@@ -5,13 +5,13 @@ import CustomComponents
import Librum.elements
import Librum.style
import Librum.icons
-import Librum.controllers
+import Librum.controllers
Popup {
id: root
property string word
property var previouslyFocusedPage
-
+
implicitWidth: 500
implicitHeight: 540
padding: 16
@@ -23,63 +23,50 @@ Popup {
border.width: 1
border.color: Style.colorContainerBorder
}
-
+
onOpened: {
- previouslyFocusedPage = activeFocusItem;
- root.forceActiveFocus();
+ previouslyFocusedPage = activeFocusItem
+ root.forceActiveFocus()
}
-
- onClosed: DictionaryController.clearData();
-
- Connections
- {
+
+ onClosed: DictionaryController.clearData()
+
+ Connections {
target: DictionaryController
-
+
function onStartedGettingDefinition() {
- loadingAnimation.playing = true;
- loadingAnimation.visible = true;
+ loadingAnimation.playing = true
+ loadingAnimation.visible = true
language.text = ""
-
- dictionaryList.visible = false;
- notFound.visible = false;
+
+ dictionaryList.visible = false
+ notFound.visible = false
}
-
+
function onGettingDefinitionFailed() {
- loadingAnimation.playing = false;
- loadingAnimation.visible = false;
-
- notFound.visible = true;
+ loadingAnimation.playing = false
+ loadingAnimation.visible = false
+
+ notFound.visible = true
}
-
+
function onGettingDefinitionSucceeded() {
- loadingAnimation.playing = false;
- loadingAnimation.visible = false;
- language.text = DictionaryController.definition.wordTypes[0].language;
-
- dictionaryList.visible = true;
+ loadingAnimation.playing = false
+ loadingAnimation.visible = false
+ language.text = DictionaryController.definition.wordTypes[0].language
+
+ dictionaryList.visible = true
}
}
-
- MouseArea
- {
- id: actionArea
- anchors.fill: parent
- cursorShape: Qt.ArrowCursor
- hoverEnabled: true
- onContainsMouseChanged: root.previouslyFocusedPage.resetCursorToDefault()
- }
-
- ColumnLayout
- {
+
+ ColumnLayout {
anchors.fill: parent
-
- RowLayout
- {
+
+ RowLayout {
Layout.fillWidth: true
spacing: 8
-
- MButton
- {
+
+ MButton {
id: backButton
Layout.preferredWidth: 32
Layout.preferredHeight: 32
@@ -88,26 +75,23 @@ Popup {
imagePath: Icons.readingViewBack
imageSize: 8
opacityOnPressed: 0.7
-
+
onClicked: DictionaryController.goToPreviousWord()
}
-
- Pane
- {
+
+ Pane {
id: container
Layout.fillWidth: true
Layout.preferredHeight: 32
padding: 0
- background: Rectangle
- {
+ background: Rectangle {
color: Style.colorContainerBackground
border.width: 1
border.color: Style.colorContainerBorder
radius: 5
}
-
- TextField
- {
+
+ TextField {
id: inputField
anchors.fill: parent
horizontalAlignment: Text.AlignLeft
@@ -119,20 +103,19 @@ Popup {
placeholderText: "Search"
placeholderTextColor: Style.colorPlaceholderText
selectByMouse: true
- background: Rectangle
- {
+ background: Rectangle {
anchors.fill: parent
radius: 4
color: "transparent"
}
-
- onEditingFinished: DictionaryController.getDefinitionForWord(text);
+
+ onEditingFinished: DictionaryController.getDefinitionForWord(
+ text)
}
}
}
-
- Label
- {
+
+ Label {
text: root.word.toUpperCase()
Layout.fillWidth: true
Layout.maximumHeight: 30
@@ -142,33 +125,30 @@ Popup {
color: Style.colorText
font.pointSize: 20
font.weight: Font.DemiBold
-
+
clip: true
}
-
- Label
- {
+
+ Label {
id: language
Layout.topMargin: -4
color: Style.colorText
font.pointSize: 11
}
-
- Pane
- {
+
+ Pane {
id: contentPane
Layout.fillWidth: true
Layout.fillHeight: true
Layout.topMargin: 22
padding: 12
- background: Rectangle
- {
+ background: Rectangle {
color: Style.colorControlBackground
border.width: 1
border.color: Style.colorContainerBorder
radius: 5
}
-
+
AnimatedImage {
id: loadingAnimation
anchors.centerIn: parent
@@ -176,9 +156,8 @@ Popup {
width: 110
fillMode: Image.PreserveAspectFit
}
-
- ListView
- {
+
+ ListView {
id: dictionaryList
anchors.fill: parent
model: DictionaryController.definition.wordTypes.length
@@ -186,39 +165,34 @@ Popup {
clip: true
boundsBehavior: Flickable.StopAtBounds
boundsMovement: Flickable.StopAtBounds
-
+
ScrollBar.vertical: ScrollBar {
visible: dictionaryList.contentHeight > dictionaryList.height
}
-
- delegate: Item
- {
+
+ delegate: Item {
id: type
property int index: modelData
-
+
width: dictionaryList.width
height: clmLayout.implicitHeight
-
- ColumnLayout
- {
+
+ ColumnLayout {
id: clmLayout
width: parent.width
spacing: 2
-
- RowLayout
- {
+
+ RowLayout {
width: parent.width
-
- Rectangle
- {
+
+ Rectangle {
id: numberCircle
color: Style.colorBasePurple
width: 22
height: width
radius: width
-
- Label
- {
+
+ Label {
anchors.centerIn: parent
text: modelData + 1
color: Style.colorBannerText
@@ -226,9 +200,8 @@ Popup {
font.bold: true
}
}
-
- Label
- {
+
+ Label {
id: partOfSpeech
Layout.fillWidth: true
Layout.leftMargin: 4
@@ -242,33 +215,29 @@ Popup {
textFormat: Text.RichText
}
}
-
- Repeater
- {
+
+ Repeater {
id: repeater
model: DictionaryController.definition.wordTypes[type.index].definitions.length
-
+
delegate: Item {
id: definitionItem
property int index: modelData
-
+
Layout.topMargin: 6
Layout.leftMargin: 32
Layout.fillWidth: true
Layout.preferredHeight: defLayout.implicitHeight
-
- ColumnLayout
- {
+
+ ColumnLayout {
id: defLayout
width: parent.width
-
- RowLayout
- {
+
+ RowLayout {
Layout.fillWidth: true
spacing: 4
-
- Label
- {
+
+ Label {
text: (modelData + 1) + "."
Layout.alignment: Qt.AlignTop
wrapMode: Text.WordWrap
@@ -276,9 +245,8 @@ Popup {
font.pointSize: 11
textFormat: Text.RichText
}
-
- Label
- {
+
+ Label {
id: definitionText
Layout.fillWidth: true
text: DictionaryController.definition.wordTypes[type.index].definitions[modelData].definition
@@ -286,51 +254,57 @@ Popup {
color: Style.colorText
font.pointSize: 11
textFormat: Text.RichText
-
- MouseArea
- {
+
+ MouseArea {
id: mouseArea
anchors.fill: parent
cursorShape: definitionText.hoveredLink !== "" ? Qt.PointingHandCursor : Qt.ArrowCursor
-
- onClicked: followWiktionaryLink()
-
+
+ onClicked: followWiktionaryLink(
+ )
+
function followWiktionaryLink() {
- if(definitionText.hoveredLink !== "")
- {
- let link = definitionText.hoveredLink;
- if(link.startsWith("http"))
- {
- Qt.openUrlExternally(link);
- return;
- }
- else if(link.startsWith("/wiki/Wiktionary"))
- {
- Qt.openUrlExternally("https://wiktionary.org/" + link);
+ if (definitionText.hoveredLink !== "") {
+ let link = definitionText.hoveredLink
+ if (link.startsWith(
+ "http")) {
+ Qt.openUrlExternally(
+ link)
+ return
+ } else if (link.startsWith(
+ "/wiki/Wiktionary")) {
+ Qt.openUrlExternally(
+ "https://wiktionary.org/"
+ + link)
return
}
-
+
// Some words have metadata pre/appended to the link
// which we need to remove before searching for the word.
- let fixedWord = link;
- if(link.startsWith("/wiki/"))
- fixedWord = link.replace("/wiki/","");
- if(fixedWord.startsWith("Appendix:Glossary#"))
- fixedWord = fixedWord.replace("Appendix:Glossary#", "");
-
- DictionaryController.getDefinitionForWord(fixedWord);
+ let fixedWord = link
+ if (link.startsWith(
+ "/wiki/"))
+ fixedWord = link.replace(
+ "/wiki/",
+ "")
+ if (fixedWord.startsWith(
+ "Appendix:Glossary#"))
+ fixedWord = fixedWord.replace(
+ "Appendix:Glossary#",
+ "")
+
+ DictionaryController.getDefinitionForWord(
+ fixedWord)
}
}
}
}
}
-
- Repeater
- {
+
+ Repeater {
model: DictionaryController.definition.wordTypes[type.index].definitions[definitionItem.index].examples.length
-
- delegate: Label
- {
+
+ delegate: Label {
id: example
Layout.fillWidth: true
Layout.leftMargin: 28
@@ -348,21 +322,18 @@ Popup {
}
}
}
-
- Item
- {
+
+ Item {
id: notFound
anchors.fill: parent
visible: false
-
- ColumnLayout
- {
+
+ ColumnLayout {
width: parent.width
anchors.centerIn: parent
spacing: 4
-
- Image
- {
+
+ Image {
id: warningIllustration
z: 2
Layout.alignment: Qt.AlignHCenter
@@ -371,34 +342,34 @@ Popup {
sourceSize.width: 180
fillMode: Image.PreserveAspectFit
}
-
- Label
- {
+
+ Label {
color: Style.colorText
Layout.alignment: Qt.AlignHCenter
font.pointSize: 14
text: "No definitions found"
}
-
+
Label {
id: searchOnlineLink
Layout.alignment: Qt.AlignHCenter
Layout.topMargin: 4
- text: 'Search online'
+ text: 'Search online'
textFormat: Text.RichText
- onLinkActivated: (link) => Qt.openUrlExternally(link)
+ onLinkActivated: link => Qt.openUrlExternally(link)
font.pointSize: 14
color: Style.colorText
-
- MouseArea
- {
+
+ MouseArea {
anchors.fill: parent
- cursorShape: searchOnlineLink.hoveredLink !== "" ? Qt.PointingHandCursor : Qt.ArrowCursor
-
- onClicked:
- {
- if(searchOnlineLink.hoveredLink !== "")
- Qt.openUrlExternally("https://google.com/search?q=" + root.word);
+ cursorShape: searchOnlineLink.hoveredLink
+ !== "" ? Qt.PointingHandCursor : Qt.ArrowCursor
+
+ onClicked: {
+ if (searchOnlineLink.hoveredLink !== "")
+ Qt.openUrlExternally(
+ "https://google.com/search?q=" + root.word)
}
}
}
@@ -406,7 +377,7 @@ Popup {
}
}
}
-
+
Label {
id: wiktionaryLink
anchors.right: parent.right
@@ -414,21 +385,20 @@ Popup {
anchors.bottomMargin: -21
anchors.rightMargin: 2
horizontalAlignment: Text.AlignRight
- text: 'Source: Wiktionary'
+ text: 'Source: Wiktionary'
textFormat: Text.RichText
font.pointSize: 9
color: Style.colorText
-
- MouseArea
- {
+
+ MouseArea {
anchors.fill: parent
cursorShape: wiktionaryLink.hoveredLink !== "" ? Qt.PointingHandCursor : Qt.ArrowCursor
-
- onClicked:
- {
- if(wiktionaryLink.hoveredLink !== "")
- Qt.openUrlExternally(wiktionaryLink.hoveredLink);
+
+ onClicked: {
+ if (wiktionaryLink.hoveredLink !== "")
+ Qt.openUrlExternally(wiktionaryLink.hoveredLink)
}
}
}
-}
\ No newline at end of file
+}
diff --git a/src/presentation/readingPage/MSelectionOptionsPopup.qml b/src/presentation/readingPage/MSelectionOptionsPopup.qml
index 1da209532..b2270f63c 100644
--- a/src/presentation/readingPage/MSelectionOptionsPopup.qml
+++ b/src/presentation/readingPage/MSelectionOptionsPopup.qml
@@ -82,8 +82,6 @@ Popup {
anchors.fill: parent
cursorShape: Qt.PointingHandCursor
hoverEnabled: true
- onContainsMouseChanged: if (typeof activeFocusItem.setPointingCursor === "function")
- activeFocusItem.setPointingCursor()
onClicked: {
action.clickedFunction()