-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved spelling context menu item to nearest place to mouse.
- Loading branch information
Showing
5 changed files
with
93 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// This file is part of Desktop App Toolkit, | ||
// a set of libraries for developing nice desktop applications. | ||
// | ||
// For license and copyright information please follow this link: | ||
// https://github.com/desktop-app/legal/blob/master/LEGAL | ||
// | ||
|
||
#include "spellcheck/spelling_highlighter.h" | ||
|
||
#include "styles/palette.h" | ||
#include "styles/style_widgets.h" | ||
#include "ui/platform/ui_platform_utility.h" | ||
|
||
#include <QtWidgets/QApplication> | ||
#include <QtWidgets/QDesktopWidget> | ||
|
||
namespace Spelling::Helper { | ||
|
||
namespace { | ||
|
||
const auto kFormattingItem = 1; | ||
const auto kSpellingItem = 1; | ||
|
||
} | ||
|
||
bool IsContextMenuTop(not_null<QMenu*> menu, QPoint mousePosition) { | ||
const auto &st = st::defaultMenu; | ||
const auto &stPopup = st::defaultPopupMenu; | ||
|
||
const auto itemHeight = st.itemPadding.top() | ||
+ st.itemStyle.font->height | ||
+ st.itemPadding.bottom(); | ||
const auto sepHeight = st.separatorPadding.top() | ||
+ st.separatorWidth | ||
+ st.separatorPadding.bottom(); | ||
|
||
const auto line = st::lineWidth; | ||
const auto p = Ui::Platform::TranslucentWindowsSupported(mousePosition) | ||
? stPopup.shadow.extend | ||
: style::margins(line, line, line, line); | ||
|
||
const auto additional = kFormattingItem + kSpellingItem; | ||
const auto actions = menu->actions() | ranges::to_vector; | ||
auto sepCount = ranges::count_if(actions, &QAction::isSeparator); | ||
auto itemsCount = actions.size() - sepCount; | ||
sepCount += additional; | ||
itemsCount += additional; | ||
|
||
const auto w = mousePosition - QPoint(0, p.top()); | ||
const auto r = QApplication::desktop()->screenGeometry(mousePosition); | ||
const auto height = itemHeight * itemsCount | ||
+ sepHeight * sepCount | ||
+ p.top() | ||
+ stPopup.scrollPadding.top() | ||
+ stPopup.scrollPadding.bottom() | ||
+ p.bottom(); | ||
|
||
return (w.y() + height - p.bottom() > r.y() + r.height()); | ||
} | ||
|
||
} // namespace Spelling::Helper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// This file is part of Desktop App Toolkit, | ||
// a set of libraries for developing nice desktop applications. | ||
// | ||
// For license and copyright information please follow this link: | ||
// https://github.com/desktop-app/legal/blob/master/LEGAL | ||
// | ||
|
||
namespace Spelling::Helper { | ||
|
||
[[nodiscard]] bool IsContextMenuTop( | ||
not_null<QMenu*> menu, | ||
QPoint mousePosition); | ||
|
||
} // namespace Spelling::Helper |