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 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063
|
/***********************************************************************
* ui.cpp - Example of a user interface *
* *
* This file is part of the FINAL CUT widget toolkit *
* *
* Copyright 2012-2023 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 <fstream>
#include <functional>
#include <iostream>
#include <string>
#include <vector>
#include <final/final.h>
using FKey = finalcut::FKey;
using finalcut::FColor;
using finalcut::FPoint;
using finalcut::FSize;
using namespace std::literals::string_literals;
//----------------------------------------------------------------------
// class ProgressDialog
//----------------------------------------------------------------------
class ProgressDialog final : public finalcut::FDialog
{
public:
// Constructor
explicit ProgressDialog (finalcut::FWidget* = nullptr);
// Destructor
~ProgressDialog() override;
private:
// Method
void initLayout() override;
// Event handlers
void onShow (finalcut::FShowEvent*) override;
void onTimer (finalcut::FTimerEvent*) override;
// Callback methods
void cb_reset_bar();
void cb_more_bar();
void cb_exit_bar();
// Data members
finalcut::FProgressbar progressbar{this};
finalcut::FButton reset{this};
finalcut::FButton more{this};
finalcut::FButton quit{this};
};
//----------------------------------------------------------------------
ProgressDialog::ProgressDialog (finalcut::FWidget* parent)
: finalcut::FDialog{parent}
{
//setModal();
reset.setText("&Reset");
reset.setStatusbarMessage ("Reset the progress bar");
reset.setDisable();
more.setText("&More");
more.setStatusbarMessage ("Increases the progress bar position");
more.setDisable();
quit.setText("E&xit");
quit.setDisable();
//progressbar.setPercentage(78);
reset.addCallback
(
"clicked",
this, &ProgressDialog::cb_reset_bar
);
more.addCallback
(
"clicked",
this, &ProgressDialog::cb_more_bar
);
quit.addCallback
(
"clicked",
this, &ProgressDialog::cb_exit_bar
);
}
//----------------------------------------------------------------------
ProgressDialog::~ProgressDialog() // destructor
{
delOwnTimers();
delCallback(&quit);
delCallback(&more);
delCallback(&reset);
}
//----------------------------------------------------------------------
void ProgressDialog::initLayout()
{
FDialog::setGeometry ( FPoint{int((getParentWidget()->getWidth() - 40) / 2), 7}
, FSize{40, 10} );
FDialog::setText("Progress bar");
reset.setGeometry(FPoint{2, 6}, FSize{8, 1}, false);
more.setGeometry(FPoint{15, 6}, FSize{8, 1}, false);
quit.setGeometry(FPoint{28, 6}, FSize{8, 1}, false);
progressbar.setGeometry(FPoint{2, 3}, FSize{34, 1}, false);
FDialog::initLayout();
}
//----------------------------------------------------------------------
void ProgressDialog::onShow (finalcut::FShowEvent*)
{
addTimer(15); // Starts the timer every 15 ms
}
//----------------------------------------------------------------------
void ProgressDialog::onTimer (finalcut::FTimerEvent*)
{
auto p = progressbar.getPercentage();
p++;
progressbar.setPercentage(p);
flush();
if ( p != 100 )
return;
delOwnTimers();
activateWindow();
raiseWindow();
reset.setEnable();
reset.setFocus();
more.setEnable();
quit.setEnable();
redraw();
finalcut::drawStatusBarMessage();
}
//----------------------------------------------------------------------
void ProgressDialog::cb_reset_bar()
{
progressbar.reset();
}
//----------------------------------------------------------------------
void ProgressDialog::cb_more_bar()
{
auto p = progressbar.getPercentage();
p++;
progressbar.setPercentage(p);
}
//----------------------------------------------------------------------
void ProgressDialog::cb_exit_bar()
{
close();
}
//----------------------------------------------------------------------
// class TextWindow
//----------------------------------------------------------------------
class TextWindow final : public finalcut::FDialog
{
public:
// Constructor
explicit TextWindow (finalcut::FWidget* = nullptr);
// Method
void append (const finalcut::FString&);
private:
// Method
void initLayout() override;
void adjustSize() override;
// Data members
finalcut::FTextView scrolltext{this};
};
//----------------------------------------------------------------------
TextWindow::TextWindow (finalcut::FWidget* parent)
: finalcut::FDialog{parent}
{
scrolltext.ignorePadding();
scrolltext.setFocus();
scrolltext.insert(" -----------------------------------------------\n"
" line 1\n"
" -----------------------------------------------\n"
" line 3\n"
" line 4"
, -1);
scrolltext.replaceRange(" File viewer", 1, 1);
scrolltext.deleteRange(3, 4);
}
//----------------------------------------------------------------------
void TextWindow::append (const finalcut::FString& str)
{
scrolltext.append(str);
}
//----------------------------------------------------------------------
void TextWindow::initLayout()
{
scrolltext.setGeometry (FPoint{1, 2}, FSize{getWidth(), getHeight() - 1});
setMinimumSize (FSize{51, 6});
FDialog::initLayout();
}
//----------------------------------------------------------------------
void TextWindow::adjustSize()
{
finalcut::FDialog::adjustSize();
scrolltext.setGeometry (FPoint{1, 2}, FSize(getWidth(), getHeight() - 1));
}
//----------------------------------------------------------------------
// class MyDialog
//----------------------------------------------------------------------
class MyDialog final : public finalcut::FDialog
{
public:
// Constructor
explicit MyDialog (finalcut::FWidget* = nullptr);
private:
// Methods
void init();
void initMenu();
void initMenuCallbacks();
void initFileMenuCallbacks();
void initEditMenuCallbacks();
void initViewMenuCallbacks();
void initHelpMenuCallback();
void initStatusBarCallbacks();
void initWidgets();
void initFlatButtons();
void initToggleButtons();
void initButtons();
void initLabels();
void initWidgetsCallbacks();
void initLayout() override;
void adjustSize() override;
// Event handlers
void onClose (finalcut::FCloseEvent*) override;
// Callback methods
void cb_noFunctionMsg (const finalcut::FButton&);
void cb_about();
void cb_terminfo();
void cb_drives();
void cb_cutClipboard();
void cb_copyClipboard();
void cb_pasteClipboard();
void cb_clearInput();
void cb_switchTheme (const finalcut::FCheckMenuItem*);
void cb_input2buttonText ( finalcut::FButton&
, const finalcut::FLineEdit& ) const;
void cb_setTitlebar (const finalcut::FLineEdit&);
void cb_showProgressBar();
void cb_updateNumber();
void cb_activateButton ( const finalcut::FRadioButton&
, finalcut::FButton& ) const;
void cb_view (const finalcut::FMenuItem*);
void cb_setInput (const finalcut::FListBox&, finalcut::FLineEdit&) const;
// Data members
bool initialized{false};
finalcut::FMenuBar Menubar{this};
// Menu bar items
finalcut::FMenu File{"&File", &Menubar};
finalcut::FMenu Edit{"&Edit", &Menubar};
finalcut::FMenu View{"&View", &Menubar};
finalcut::FMenuItem Options{"&Options", &Menubar};
finalcut::FDialogListMenu Window{"&Window", &Menubar};
finalcut::FMenuItem Help{"&Help", &Menubar};
// "File" menu items
finalcut::FMenuItem Open{"&Open...", &File};
finalcut::FMenu Recent{"&System files", &File};
finalcut::FMenuItem Line1{&File};
finalcut::FMenuItem Quit{"&Quit", &File};
// "Recent" menu items
finalcut::FMenuItem File1{"/etc/services", &Recent};
finalcut::FMenuItem File2{"/etc/fstab", &Recent};
finalcut::FMenuItem File3{"/etc/passwd", &Recent};
// "Edit" menu items
finalcut::FMenuItem Undo{FKey::Ctrl_z, "Undo", &Edit};
finalcut::FMenuItem Redo{FKey::Ctrl_y, "Redo", &Edit};
finalcut::FMenuItem Line2{&Edit};
finalcut::FMenuItem Cut{FKey::Ctrl_x, "Cu&t", &Edit};
finalcut::FMenuItem Copy{FKey::Ctrl_c, "&Copy", &Edit};
finalcut::FMenuItem Paste{FKey::Ctrl_v, "&Paste", &Edit};
finalcut::FMenuItem Clear{FKey::Del_char, "C&lear", &Edit};
// "View" menu items
finalcut::FMenuItem Env{"&Terminal...", &View};
finalcut::FMenuItem Drive{"&Drive symbols...", &View};
finalcut::FMenuItem Line3{&View};
finalcut::FCheckMenuItem Theme{"Dark &mode", &View};
// Statusbar
finalcut::FStatusBar Statusbar{this};
finalcut::FStatusKey key_F1{FKey::F1, "About", &Statusbar};
finalcut::FStatusKey key_F2{FKey::F2, "View", &Statusbar};
finalcut::FStatusKey key_F3{FKey::F3, "Quit", &Statusbar};
// Dialog widgets
finalcut::FButton MyButton1{this};
finalcut::FButton MyButton2{this};
finalcut::FButton MyButton3{this};
finalcut::FButtonGroup radioButtonGroup{"Button", this};
finalcut::FRadioButton radio1{"E&nable", &radioButtonGroup};
finalcut::FRadioButton radio2{&radioButtonGroup};
finalcut::FButtonGroup checkButtonGroup{"Options", this};
finalcut::FCheckBox check1{"&Bitmode", &checkButtonGroup};
finalcut::FCheckBox check2{"&8-Bit", &checkButtonGroup};
finalcut::FLineEdit myLineEdit{this};
finalcut::FButton MyButton4{this};
finalcut::FButton MyButton5{this};
finalcut::FButton MyButton6{this};
finalcut::FListBox myList{this};
finalcut::FLabel headline{this};
finalcut::FLabel tagged{L"Tagged:", this};
finalcut::FLabel tagged_count{this};
finalcut::FLabel sum{L"Sum:", this};
finalcut::FLabel sum_count{this};
finalcut::FString clipboard{};
};
//----------------------------------------------------------------------
MyDialog::MyDialog (finalcut::FWidget* parent)
: finalcut::FDialog{parent}
{
init();
}
//----------------------------------------------------------------------
void MyDialog::init()
{
initMenu(); // Initialize the program menu
initMenuCallbacks(); // Initialize program menu callbacks
initStatusBarCallbacks(); // Initialize status bar callbacks
initWidgets(); // Initialize the dialog widgets
initWidgetsCallbacks(); // Initialize dialog widget callbacks
initialized = true;
}
//----------------------------------------------------------------------
void MyDialog::initMenu()
{
// Menu bar items
File.setStatusbarMessage ("File management commands");
Edit.setStatusbarMessage ("Cut-and-paste editing commands");
View.setStatusbarMessage ("Show internal informations");
Options.setStatusbarMessage ("Set program defaults");
Options.setDisable();
Window.setStatusbarMessage ("List of all the active dialogs");
Help.setStatusbarMessage ("Show version and copyright information");
// "File" menu items
Open.addAccelerator (FKey::Ctrl_o); // Ctrl + O
Open.setStatusbarMessage ("Locate and open a text file");
Recent.setStatusbarMessage ("View text file");
Line1.setSeparator();
Quit.addAccelerator (FKey::Meta_x); // Meta/Alt + X
Quit.setStatusbarMessage ("Exit the program");
// "Edit" menu items
Undo.setDisable();
Redo.setDisable();
Line2.setSeparator();
Cut.setStatusbarMessage ( "Remove the input text"
" and put it in the clipboard" );
Copy.setStatusbarMessage ("Copy the input text into the clipboad");
Paste.setStatusbarMessage ("Insert text form clipboard");
Clear.setStatusbarMessage ("Delete input text");
// "View" menu items
Env.setStatusbarMessage ("Informations about this terminal");
Drive.setStatusbarMessage ("Show drive symbols");
Line3.setSeparator();
if ( finalcut::FStartOptions::getInstance().dark_theme )
Theme.setChecked();
}
//----------------------------------------------------------------------
void MyDialog::initMenuCallbacks()
{
// Menu function callbacks
initFileMenuCallbacks();
initEditMenuCallbacks();
initViewMenuCallbacks();
initHelpMenuCallback();
}
//----------------------------------------------------------------------
void MyDialog::initFileMenuCallbacks()
{
// File menu
Open.addCallback
(
"clicked",
this, &MyDialog::cb_view,
nullptr
);
Quit.addCallback
(
"clicked",
finalcut::getFApplication(),
&finalcut::FApplication::cb_exitApp,
this
);
// System files submenu
File1.addCallback
(
"clicked",
this, &MyDialog::cb_view,
&File1
);
File2.addCallback
(
"clicked",
this, &MyDialog::cb_view,
&File2
);
File3.addCallback
(
"clicked",
this, &MyDialog::cb_view,
&File3
);
}
//----------------------------------------------------------------------
void MyDialog::initEditMenuCallbacks()
{
// Edit menu
Cut.addCallback
(
"clicked",
this, &MyDialog::cb_cutClipboard
);
Copy.addCallback
(
"clicked",
this, &MyDialog::cb_copyClipboard
);
Paste.addCallback
(
"clicked",
this, &MyDialog::cb_pasteClipboard
);
Clear.addCallback
(
"clicked",
this, &MyDialog::cb_clearInput
);
}
//----------------------------------------------------------------------
void MyDialog::initViewMenuCallbacks()
{
// View menu
Env.addCallback
(
"clicked",
this, &MyDialog::cb_terminfo
);
Drive.addCallback
(
"clicked",
this, &MyDialog::cb_drives
);
Theme.addCallback
(
"clicked",
this, &MyDialog::cb_switchTheme,
&Theme
);
}
//----------------------------------------------------------------------
void MyDialog::initHelpMenuCallback()
{
Help.addCallback
(
"clicked",
this, &MyDialog::cb_about
);
}
//----------------------------------------------------------------------
void MyDialog::initStatusBarCallbacks()
{
// Add statusbar function callbacks
key_F1.addCallback
(
"activate",
this, &MyDialog::cb_about
);
key_F2.addCallback
(
"activate",
this, &MyDialog::cb_view,
nullptr
);
key_F3.addCallback
(
"activate",
finalcut::getFApplication(),
&finalcut::FApplication::cb_exitApp,
this
);
}
//----------------------------------------------------------------------
void MyDialog::initWidgets()
{
// Flat buttons
initFlatButtons();
// Radio buttons and check boxes
initToggleButtons();
// A text input field
myLineEdit.setLabelText (L"&Input");
myLineEdit.setStatusbarMessage ("Press Enter to set the title");
myLineEdit << finalcut::FString{"EnTry"}.toLower();
// Buttons
initButtons();
// A multiple selection listbox
myList.setText ("Items");
myList.setStatusbarMessage ("99 items in a list");
myList.setMultiSelection();
myList.reserve(100);
for (auto z{1}; z < 100; z++)
myList.insert (finalcut::FString{} << z << L" placeholder");
// Text labels
initLabels();
}
//----------------------------------------------------------------------
void MyDialog::initFlatButtons()
{
// Flat buttons
MyButton1.setText (L"&SIN");
MyButton1.setStatusbarMessage ("Sine function");
MyButton1.setNoUnderline();
MyButton1.setFlat();
MyButton2.setText (L"&COS");
MyButton2.setStatusbarMessage ("Cosine function");
MyButton2.setNoUnderline();
MyButton2.setFlat();
MyButton3.setText (L"&=");
MyButton3.setStatusbarMessage ("Equal");
MyButton3.setNoUnderline();
MyButton3.setFlat();
// Add button callback functions
MyButton1.addCallback
(
"clicked",
this, &MyDialog::cb_noFunctionMsg,
std::ref(MyButton1)
);
MyButton2.addCallback
(
"clicked",
this, &MyDialog::cb_noFunctionMsg,
std::ref(MyButton2)
);
MyButton3.addCallback
(
"clicked",
this, &MyDialog::cb_noFunctionMsg,
std::ref(MyButton3)
);
}
//----------------------------------------------------------------------
void MyDialog::initToggleButtons()
{
// Radio buttons in a group
//radioButtonGroup->unsetBorder();
radio1.setStatusbarMessage ("Enable button Test");
radio2.setText ("&Disable");
radio2.setStatusbarMessage ("Disable button Test");
radio2.setChecked();
//radio2.setDisable();
// Checkboxes in a group
check1.setNoUnderline();
check2.setChecked();
check2.setNoUnderline();
}
//----------------------------------------------------------------------
void MyDialog::initButtons()
{
// Buttons
MyButton4.setText (L"&Get input");
MyButton4.setStatusbarMessage ("Take text from input field");
MyButton4.setFocus();
MyButton5.setText (L"&Test");
MyButton5.setStatusbarMessage ("Progressbar testing dialog");
MyButton5.setDisable();
MyButton6.setText (L"&Quit");
MyButton6.setStatusbarMessage ("Exit the program");
MyButton6.addAccelerator(FKey('x'));
// Add button callback functions
MyButton4.addCallback
(
"clicked",
this, &MyDialog::cb_input2buttonText,
std::ref(MyButton4), std::cref(myLineEdit)
);
MyButton5.addCallback
(
"clicked",
this, &MyDialog::cb_showProgressBar
);
MyButton6.addCallback
(
"clicked",
finalcut::getFApplication(),
&finalcut::FApplication::cb_exitApp,
this
);
}
//----------------------------------------------------------------------
void MyDialog::initLabels()
{
// Text labels
headline.setEmphasis();
headline.setAlignment (finalcut::Align::Center);
headline = L"List items";
tagged_count << 0;
sum.setAlignment (finalcut::Align::Right);
sum_count << myList.getCount();
}
//----------------------------------------------------------------------
void MyDialog::initWidgetsCallbacks()
{
// Add some function callbacks
myLineEdit.addCallback
(
"activate", // e.g. on <Enter>
this, &MyDialog::cb_setTitlebar,
std::ref(myLineEdit)
);
radio1.addCallback
(
"toggled",
this, &MyDialog::cb_activateButton,
std::ref(radio1), std::ref(MyButton5)
);
myList.addCallback
(
"clicked",
this, &MyDialog::cb_setInput,
std::ref(myList), std::ref(myLineEdit)
);
myList.addCallback
(
"row-selected",
this, &MyDialog::cb_updateNumber
);
}
//----------------------------------------------------------------------
void MyDialog::initLayout()
{
MyButton1.setGeometry(FPoint{3, 3}, FSize{5, 1});
MyButton1.setDoubleFlatLine (finalcut::Side::Bottom);
MyButton2.setGeometry(FPoint{3, 5}, FSize{5, 1});
MyButton2.setDoubleFlatLine (finalcut::Side::Top);
MyButton3.setGeometry(FPoint{10, 3}, FSize{5, 3});
MyButton4.setGeometry(FPoint{20, 8}, FSize{12, 1});
MyButton5.setGeometry(FPoint{20, 11}, FSize{12, 1});
MyButton6.setGeometry(FPoint{20, 14}, FSize{12, 1});
radioButtonGroup.setGeometry(FPoint{3, 8}, FSize{14, 4});
radio1.setGeometry(FPoint{1, 1}, FSize{10, 1});
radio2.setGeometry(FPoint{1, 2}, FSize{11, 1});
checkButtonGroup.setGeometry(FPoint{3, 12}, FSize{14, 4});
check1.setGeometry(FPoint{1, 1}, FSize{11, 1});
check2.setGeometry(FPoint{1, 2}, FSize{9, 1});
headline.setGeometry(FPoint{21, 3}, FSize{10, 1});
tagged.setGeometry(FPoint{21, 4}, FSize{7, 1});
tagged_count.setGeometry(FPoint{29, 4}, FSize{5, 1});
sum.setGeometry(FPoint{21, 5}, FSize{7, 3});
sum_count.setGeometry(FPoint{29, 5}, FSize{5, 3});
myLineEdit.setGeometry(FPoint{22, 1}, FSize{10, 1});
myList.setGeometry(FPoint{38, 1}, FSize{14, 17});
FDialog::initLayout();
}
//----------------------------------------------------------------------
void MyDialog::adjustSize()
{
auto h = getDesktopHeight();
if ( h > 4 )
h -= 4;
setHeight (h, false);
finalcut::FDialog::adjustSize(); // with new client area size
auto x = int((getDesktopWidth() - getWidth()) / 2);
if ( x < 1 )
x = 1;
setPos (FPoint{x, 2}, false);
if ( initialized && h > 3 )
myList.setHeight (h - 3, true);
}
//----------------------------------------------------------------------
void MyDialog::onClose (finalcut::FCloseEvent* ev)
{
finalcut::FApplication::closeConfirmationDialog (this, ev);
}
//----------------------------------------------------------------------
void MyDialog::cb_noFunctionMsg (const finalcut::FButton& button)
{
auto text = button.getText();
text = text.replace('&', "");
finalcut::FMessageBox::error ( this
, "The \"" + text + "\" button has\n"
"no function");
}
//----------------------------------------------------------------------
void MyDialog::cb_about()
{
const finalcut::FString line(2, finalcut::UniChar::BoxDrawingsHorizontal);
finalcut::FMessageBox info ( "About"
, line + L" FINAL CUT " + line + L"\n\n"
L"Version " + finalcut::fc_release + L"\n\n"
L"(c) 2023 by Markus Gans"
, finalcut::FMessageBox::ButtonType::Ok
, finalcut::FMessageBox::ButtonType::Reject
, finalcut::FMessageBox::ButtonType::Reject
, this );
info.setCenterText();
info.show();
}
//----------------------------------------------------------------------
void MyDialog::cb_terminfo()
{
const auto x = getDesktopWidth();
const auto y = getDesktopHeight();
finalcut::FMessageBox info1 \
(
"Environment"
, std::move(finalcut::FString()
<< " Type: " << finalcut::FTerm::getTermType() << "\n"
<< " Name: " << finalcut::FTerm::getTermFileName() << "\n"
<< " Mode: " << finalcut::FTerm::getEncodingString() << "\n"
<< " Size: " << x << finalcut::UniChar::Times
<< y << "\n"
<< "Colors: " << finalcut::FVTerm::getFOutput()->getMaxColor())
, finalcut::FMessageBox::ButtonType::Ok
, finalcut::FMessageBox::ButtonType::Reject
, finalcut::FMessageBox::ButtonType::Reject
, this
);
info1.setHeadline("Terminal:");
info1.exec();
}
//----------------------------------------------------------------------
void MyDialog::cb_drives()
{
finalcut::FMessageBox info2 \
(
"Drive symbols"
, "Generic: \n\n"
"Network: \n\n"
" CD:"
, finalcut::FMessageBox::ButtonType::Ok
, finalcut::FMessageBox::ButtonType::Reject
, finalcut::FMessageBox::ButtonType::Reject
, this
);
if ( finalcut::FVTerm::getFOutput()->isNewFont() )
{
finalcut::FLabel drive {finalcut::NF_Drive, &info2};
drive.setGeometry (FPoint{11, 2}, FSize{4, 1});
finalcut::FLabel net {finalcut::NF_Net_Drive, &info2};
net.setGeometry (FPoint{11, 4}, FSize{4, 1});
finalcut::FLabel cd {finalcut::NF_CD_ROM, &info2};
cd.setGeometry (FPoint{11, 6}, FSize{4, 1});
info2.exec();
}
else
{
finalcut::FLabel drive {" - ", &info2};
drive.setGeometry (FPoint{11, 2}, FSize{4, 1});
finalcut::FLabel net {" N ", &info2};
net.setGeometry (FPoint{11, 4}, FSize{4, 1});
finalcut::FLabel cd {" CD ", &info2};
cd.setGeometry (FPoint{11, 6}, FSize{4, 1});
if ( finalcut::FVTerm::getFOutput()->isMonochron() )
{
net.setReverseMode();
drive.setReverseMode();
cd.setReverseMode();
}
else
{
net.setForegroundColor (FColor::White);
net.setBackgroundColor (FColor::DarkGray);
drive.setForegroundColor (FColor::White);
drive.setBackgroundColor (FColor::DarkGray);
cd.setForegroundColor (FColor::White);
cd.setBackgroundColor (FColor::DarkGray);
}
info2.exec();
}
}
//----------------------------------------------------------------------
void MyDialog::cb_cutClipboard()
{
clipboard = myLineEdit.getText();
myLineEdit.clear();
myLineEdit.redraw();
}
//----------------------------------------------------------------------
void MyDialog::cb_copyClipboard()
{
clipboard = myLineEdit.getText();
}
//----------------------------------------------------------------------
void MyDialog::cb_pasteClipboard()
{
myLineEdit = clipboard;
myLineEdit.redraw();
}
//----------------------------------------------------------------------
void MyDialog::cb_clearInput()
{
clipboard.clear();
myLineEdit.clear();
myLineEdit.redraw();
}
//----------------------------------------------------------------------
void MyDialog::cb_switchTheme (const finalcut::FCheckMenuItem* check_menu)
{
if ( check_menu->isChecked() )
finalcut::FApplication::setDarkTheme();
else
finalcut::FApplication::setDefaultTheme();
auto root_widget = getRootWidget();
root_widget->resetColors();
root_widget->redraw();
}
//----------------------------------------------------------------------
void MyDialog::cb_input2buttonText ( finalcut::FButton& button
, const finalcut::FLineEdit& lineedit ) const
{
button.setText(lineedit.getText());
button.redraw();
}
//----------------------------------------------------------------------
void MyDialog::cb_setTitlebar (const finalcut::FLineEdit& lineedit)
{
finalcut::FString title{};
lineedit >> title;
finalcut::FTerm::setTermTitle (title);
setText (title);
redraw();
}
//----------------------------------------------------------------------
void MyDialog::cb_showProgressBar()
{
auto p_dgl = new ProgressDialog(this);
p_dgl->show();
}
//----------------------------------------------------------------------
void MyDialog::cb_updateNumber()
{
int select_num = 0;
for (const auto& item : myList.getData() )
if ( item.isSelected() )
select_num++;
tagged_count.clear();
tagged_count << select_num;
tagged_count.redraw();
}
//----------------------------------------------------------------------
void MyDialog::cb_activateButton ( const finalcut::FRadioButton& rb
, finalcut::FButton& button) const
{
if ( rb.isChecked() )
button.setEnable();
else
button.setDisable();
button.redraw();
}
//----------------------------------------------------------------------
void MyDialog::cb_view (const finalcut::FMenuItem* item)
{
finalcut::FString file = [&item, this] ()
{
if ( item && ! item->getText().isEmpty() )
return item->getText();
return finalcut::FFileDialog::fileOpenChooser (this);
}();
if ( file.isEmpty() )
return;
const auto& view = new TextWindow(this);
finalcut::FString filename(basename(const_cast<char*>(file.c_str())));
view->setText ("Viewer: " + filename);
view->setGeometry ( FPoint { 1 + int((getRootWidget()->getWidth() - 60) / 2)
, int(getRootWidget()->getHeight() / 6) }
, FSize{60, getRootWidget()->getHeight() * 3 / 4} );
view->setMinimizable();
view->setResizeable();
std::string line{};
std::ifstream infile;
infile.open(file.c_str());
while ( ! infile.eof() && infile.good() )
{
getline(infile, line);
view->append(line);
}
if ( infile.is_open() )
infile.close();
view->show();
}
//----------------------------------------------------------------------
void MyDialog::cb_setInput ( const finalcut::FListBox& listbox
, finalcut::FLineEdit& lineedit) const
{
lineedit = listbox.getItem(listbox.currentItem()).getText();
lineedit.redraw();
}
//----------------------------------------------------------------------
// main part
//----------------------------------------------------------------------
auto main (int argc, char* argv[]) -> int
{
const finalcut::FString title { "FINAL CUT "s + finalcut::fc_release
+ " (C) 2023 by Markus Gans" };
// Create the application object app
finalcut::FApplication app{argc, argv};
finalcut::FVTerm::setNonBlockingRead();
// Create main dialog object d
MyDialog d{&app};
d.setText (title);
d.setSize (FSize{56, app.getHeight() - 4});
d.setShadow(); // Instead of the transparent window shadow
// Set the dialog object d as the main widget of the application.
// When you close the main widget, the application will be closed.
finalcut::FWidget::setMainWidget(&d);
// Enable the final cut graphical font
//finalcut::FVTerm::getFOutput()->setNewFont();
// Show the dialog d
d.show();
finalcut::FTerm::redefineDefaultColors(true);
finalcut::FTerm::setTermTitle (title);
// Sets the terminal size to 94×30
//app.setTerminalSize(FSize{94, 30});
// Start the application
// and return the result to the operating system
return app.exec();
}
|