1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
|
/***********************************************************************
* fullwidth-letter.cpp - Demonstrates use of full-width characters *
* *
* This file is part of the FINAL CUT widget toolkit *
* *
* Copyright 2019-2022 Markus Gans *
* *
* FINAL CUT is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation; either version 3 of *
* the License, or (at your option) any later version. *
* *
* FINAL CUT is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this program. If not, see *
* <http://www.gnu.org/licenses/>. *
***********************************************************************/
#include <final/final.h>
#define full(...) finalcut::getFullWidth(__VA_ARGS__)
using finalcut::FPoint;
using finalcut::FSize;
//----------------------------------------------------------------------
// main part
//----------------------------------------------------------------------
auto main (int argc, char* argv[]) -> int
{
// Create the application object
finalcut::FApplication app{argc, argv};
// Create a simple dialog box
finalcut::FDialog dgl{&app};
dgl.setText (full("Dialog"));
dgl.setSize (FSize{37, 16});
dgl.setPos ({ int(app.getDesktopWidth() - dgl.getWidth()) / 2
, int(app.getDesktopHeight() - dgl.getHeight()) / 2});
dgl.setShadow();
// Create input fields
finalcut::FLineEdit field1 {&dgl};
field1.setLabelText (full("Input"));
field1.setText (L"你好"); // Nǐ hǎo (chinese)
field1.setStatusbarMessage (full("Type your text here"));
field1.setGeometry (FPoint{15, 1}, FSize{19, 1});
finalcut::FLineEdit field2 {&dgl};
field2.setLabelText (L"Comment");
field2.setText (full(L"Hello"));
field2.setStatusbarMessage (full("Post a comment"));
field2.setGeometry (FPoint{15, 3}, FSize{19, 1});
// Create the button group
finalcut::FButtonGroup group {full("Side"), &dgl};
group.setGeometry(FPoint{2, 5}, FSize{32, 3});
// Create radio buttons
finalcut::FRadioButton left {"&" + full("Left"), &group};
finalcut::FRadioButton right {"&" + full("Right"), &group};
left.setStatusbarMessage (full("Prefer the left side"));
right.setStatusbarMessage (full("Prefer the right side"));
left.setGeometry (FPoint{1, 1}, FSize{8, 1});
right.setGeometry (FPoint{15, 1}, FSize{10, 1});
// Create a scrollable text field
finalcut::FTextView scroll_text {&dgl};
scroll_text.setGeometry (FPoint{2, 8}, FSize{32, 3});
finalcut::FString text_line{"FINAL CUT supports "
"full-width characters."};
scroll_text << full(text_line);
scroll_text.setStatusbarMessage ("You can scroll right and "
"left with the arrow keys");
// Create a OK button
finalcut::FButton btn {"&OK", &dgl};
btn.setStatusbarMessage (full("Press Enter to exit the dialog"));
btn.setGeometry (FPoint{24, 12}, FSize{10, 1});
// Create the status bar
finalcut::FStatusBar sbar {&dgl};
finalcut::FStatusKey key_F1 (finalcut::FKey::F1, "Info", &sbar);
// Create the menu bar
finalcut::FMenuBar Menubar {&dgl};
// Create menu bar items
finalcut::FMenu File{L"&File", &Menubar};
finalcut::FMenuItem Edit{L"&Edit", &Menubar};
finalcut::FMenuItem Exit{L"E&xit", &Menubar};
// Create file menu items
finalcut::FMenuItem Open{"&Open", &File};
finalcut::FMenuItem Print{"&Print", &File};
finalcut::FMenuItem Line{&File};
Line.setSeparator();
finalcut::FMenuItem Quit{"&Quit", &File};
Quit.addAccelerator (finalcut::FKey::Ctrl_q); // Ctrl + Q
// Callback lambda expressions
auto cb_exit = \
[] (const auto& a)
{
a.quit();
};
auto cb_tooltip = \
[] (const auto& a)
{
finalcut::FToolTip tooltip(a);
tooltip.setText (full("A tooltip with\ncharacters\n"
"in full-width\nfor 3 seconds"));
tooltip.show();
sleep(3);
};
// Connect the signals with the callback lambda expressions
btn.addCallback ("clicked", cb_exit, std::ref(app));
Exit.addCallback ("clicked", cb_exit, std::ref(app));
Quit.addCallback ("clicked", cb_exit, std::ref(app));
key_F1.addCallback ("activate", cb_tooltip, &dgl);
// Set dialog object as main widget
finalcut::FWidget::setMainWidget(&dgl);
// Show and start the application
dgl.show();
return app.exec();
}
|