File indexing completed on 2022-11-29 18:26:10

0001 #include <qapplication.h>
0002 #include <kdialog.h>
0003 #include <kguiitem.h>
0004 
0005 #include <QTextBrowser>
0006 #include <QLabel>
0007 
0008 int main(int argc, char **argv)
0009 {
0010     QApplication app(argc, argv);
0011 
0012     // -----
0013     QString text = // the explanation shown by the example dialog
0014         "<center><h1>KDialog Example</h1></center><hr><br>"
0015         "This example shows the usage of the <i>KDialog</i>  class. "
0016         "<i>KDialog</i> is the KDE user interface class used to create "
0017         "dialogs with simple layout without having to define an own dialog "
0018         "style for your application. <br>"
0019         "It provides some standards buttons that are needed in most dialogs. Each one may be "
0020         "hidden, enabled or disabled, and tooltips and quickhelp texts might be"
0021         " added. And you do not need to bother about geometry management, this "
0022         "is all done automatically.<br>"
0023         "The class supports the creation of dialogs without being forced "
0024         "to derive an own class for it, but you may derive your own class "
0025         "for a better code structure.<br>"
0026         "If you wrote a help chapter explaining what your dialog does, you "
0027         "should add a link to it to the dialog using <tt>setHelp</tt>. You do "
0028         "not have to take care about launching the help viewer, just set the "
0029         "help file and topic and of course copy it to your documentation "
0030         "directory during the program installation.";
0031     /* Create the dialog object. DialogBase is derived from QDialog, but
0032        you do not need to derive it to create a nice-looking dialog. Mostly,
0033        you already have a widget class representing the core of your dialog,
0034        and you only need to add a frame around it and the default buttons.
0035 
0036        If you want to derive it, you still can, moving all code shown here
0037        inside of your new class. */
0038     KDialog dialog;
0039     dialog.setButtons(KDialog::Ok | KDialog::Cancel | KDialog::Details | KDialog::User1 | KDialog::Help);
0040     dialog.setButtonGuiItem(KDialog::User1, KGuiItem("Test"));
0041     dialog.setCaption("dialog!");
0042     /* Set a help chapter. If you do not set one, the link is not shown, and the
0043        upper part of the frame shrinks as much as possible. The help window "
0044        "will of course only pop up if you correctly installed kdebase. */
0045     // I disabled it, as khcclient did not run for me.
0046     dialog.setHelp("kdehelp/intro.html", "");
0047     /* This QTextView is intended to be the main widget of our dialog. The
0048        main widget is placed inside the dialogs frame, with the buttons below
0049        it. You do not have to take care about the size handling, but it is a
0050        good idea to set the main wigdets minimum size, since the sizes Qt and
0051        the DialogBase class guess are sometimes ugly.
0052 
0053        It is important that your main widget is created with the dialog object
0054        as its parent! */
0055     QTextBrowser view;
0056     view.setHtml(text);
0057     dialog.setMainWidget(&view);
0058 
0059     QLabel label("this is a place for some advanced settings", &dialog);
0060     dialog.setDetailsWidget(&label);
0061 
0062     //view.setMinimumSize(400, view.heightForWidth(400)+20);
0063     view.setMinimumSize(250, 300);
0064     /* After finishing the setup of your main widget, the dialog needs to be
0065        adjusted. It is not done automatically, since the layout of the main
0066        widget may change before the dialog is shown. Additionally, setting a
0067        help chapter may cause a need for adjustment since it modifies the height
0068        of the upper frame. */
0069 // dialog.resize(dialog.minimumSize());
0070     /* The dialog object is used just as any other QDialog: */
0071     if (dialog.exec()) {
0072         qDebug("Accepted.");
0073     } else {
0074         qDebug("Rejected.");
0075     }
0076     return 0;
0077 }
0078