New bold, italic and underline shortcuts for text box.#890
New bold, italic and underline shortcuts for text box.#890kaamui merged 10 commits intoOpenBoard-org:1.7.2-devfrom
Conversation
I think the
Did you try to |
Thank you your confirmation.
Yes I see it in the doc. I tried some tests with |
|
More investigations about the italic issue show me the points below:
So now, The italic shortcut does the italic job and make a zoom in the board also... It makes me crazy. |
|
You can remove it (and ctrl+o for zoom out too). |
src/domain/UBGraphicsTextItem.cpp
Outdated
| return font; | ||
| } | ||
|
|
||
| bool UBGraphicsTextItem::event(QEvent *ev) |
There was a problem hiding this comment.
Can't you directly modify KeyPressEvent instead of checking every event to see if it's a KeyEvent ?
src/domain/UBGraphicsTextItem.cpp
Outdated
| QKeyEvent* keyEvent = static_cast<QKeyEvent*>(ev); | ||
| QKeySequence::StandardKey shortcuts[] = {QKeySequence::StandardKey::Bold, | ||
| QKeySequence::StandardKey::Italic, | ||
| QKeySequence::StandardKey::Underline}; | ||
| QKeySequence::StandardKey key = QKeySequence::StandardKey::UnknownKey; | ||
| for(int i=0; i<3; i++) | ||
| if(keyEvent->matches(shortcuts[i])) | ||
| { | ||
| key = shortcuts[i]; | ||
| break; | ||
| } | ||
| if(key != QKeySequence::StandardKey::UnknownKey) | ||
| { |
There was a problem hiding this comment.
please simplify this. In KeyPressEvent (didn't test it but something like following) :
// Is checking isSelected really necessary ? Isn't KeyPressEvent (or QGraphicsTextItem::event)
// called only when item is selected or at least on focus ?
if(event->type() == QEvent::ShortcutOverride && isSelected())
{
if (event->matches(QKeySequence::StandardKey::Bold)
|| event->matches(QKeySequence::StandardKey::Italic)
|| event->matches( QKeySequence::StandardKey::Underline))
{
QTextCursor curCursor = textCursor();
QTextCharFormat format;
QFont ft(curCursor.charFormat().font());
if(event->key() == QKeySequence::StandardKey::Bold)
ft.setBold(!ft.bold());
else if(event->key() == QKeySequence::StandardKey::Italic)
ft.setItalic(!ft.italic());
else
ft.setUnderline(!ft.underline());
format.setFont(ft);
curCursor.mergeCharFormat(format);
setTextCursor(curCursor);
contentsChanged();
event->accept();
return true; //base class call should be avoided ?
}
}There was a problem hiding this comment.
There was a problem hiding this comment.
Yes, it is better in the keyPressEvent() method.
But now, for the Italic shortcut, the main 'Ctrl+I' action to set the Pen is throw at first and the keyPressEvent() method never receives the event. So the Italic modification is impossible.
I pushed the modifications to share them because I have no idea to manage this issue.
Currently, we can:
- set
bold,underlineanditalicinevent()method - or only set
boldandunderlineinkeyPressEvent()method
src/domain/UBGraphicsTextItem.cpp
Outdated
|
|
||
| contentsChanged(); | ||
| ev->accept(); | ||
| return true; |
There was a problem hiding this comment.
Are you sure we want to avoid base class call ?
There was a problem hiding this comment.
My understanding of the keyPressEvent() documentation leads me to remove the accept() call and do not call the base class method:
Note that QKeyEvent starts with isAccepted() == true, so you do not need to call QKeyEvent::accept() - just do not call the base class implementation if you act upon the key.
https://doc.qt.io/qt-6/qwidget.html#keyPressEvent
It seems we do not call the base class method if we intercept event also for the event() method. Have a look at the example of the documentation:
https://doc.qt.io/qt-6/qobject.html#event
|
Hi @sebojolais Can you rebase your PR to thank you ! |
…t in UBGraphicsTextItem class.
…the Italic shortcut for text box item.
…t in UBGraphicsTextItem class.
753be36 to
c002624
Compare
|
Thank you for your answer. |
My usecase is :
I used to change the format of the text. For example, some words in bold or italic or underlined. And I want to go fast without opening the font dialog.
The idea is to implement the reception of events in the
UBGraphicsTextItem. And we do the text modification if the event is aboldoritalicorunderlineshortcut.I do not know if it will be better to do it in
UBGraphicsTextItemDelegate.It works fine in my side on linux and Qt 5 and 6.
The only issue is due to other
Ctrl+Ishortcut to set the stylus. Theitalicshortcut set the text in italic but also switches in stylus mode and the Text box loses the focus.