joe_vanandel

LayoutDemo.C

Dec 23rd, 2013
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.85 KB | None | 0 0
  1. /*
  2.  * Copyright (C) 2006 Wim Dumon, Koen Deforche
  3.  *
  4.  * See the LICENSE file for terms of use.
  5.  */
  6.  
  7. #include <iostream>
  8. #include <vector>
  9. #include <string>
  10.  
  11. #include <boost/format.hpp>
  12.  
  13. #include <Wt/WApplication>
  14. #include <Wt/WBreak>
  15. #include <Wt/WContainerWidget>
  16. #include <Wt/WDialog>
  17. #include <Wt/WLineEdit>
  18. #include <Wt/WPushButton>
  19. #include <Wt/WText>
  20. #include <Wt/WGridLayout>
  21. #include <Wt/WRadioButton>
  22. #include <Wt/WButtonGroup>
  23. #include <Wt/WTextArea>
  24. #include <Wt/WHBoxLayout>
  25. #include <Wt/WVBoxLayout>
  26. #include <Wt/WTabWidget>
  27. #include <Wt/WSignalMapper>
  28. #include <Wt/WPanel>
  29.  
  30.  
  31. #define ALIGN_TITLE (Wt::AlignCenter | Wt::AlignTop)
  32. #define ALIGN_TOP_LEFT (Wt::AlignLeft | Wt::AlignTop)
  33. #define ALIGN_TOP_RIGHT (Wt::AlignRight | Wt::AlignTop)
  34. #define ALIGN_TOP_CENTER (Wt::AlignCenter | Wt::AlignTop)
  35.  
  36.  
  37.  
  38. using namespace Wt;
  39. using namespace std;
  40.  
  41. /*
  42.  * demonstrate layout with tabs and panels
  43.  */
  44.  
  45.  
  46.  
  47.    
  48. class LayoutDemo : public WApplication
  49. {
  50. public:
  51.     LayoutDemo(const WEnvironment& env);
  52.    
  53.     ~LayoutDemo();
  54.  
  55. private:
  56.   WTabWidget *createTabs();
  57.   WContainerWidget *createATab(string label);
  58.   WWidget *showLog();
  59.   WWidget *showScanStatus();
  60.  
  61.   void ShowDialog();
  62.    
  63.  
  64. };
  65.  
  66.  
  67. /*
  68.  * The env argument contains information about the new session, and
  69.  * the initial request. It must be passed to the WApplication
  70.  * constructor so it is typically also an argument for your custom
  71.  * application constructor.
  72.  */
  73. LayoutDemo::LayoutDemo(const WEnvironment& env) : WApplication(env)
  74. {
  75.     useStyleSheet("layoutDemo.css");
  76.     setCssTheme("polished");
  77.     setTitle("Layout Demo Test ");                  // application title
  78.  
  79.     WContainerWidget *outerContainer = new WContainerWidget(WApplication::instance()->root());
  80.    
  81.     WVBoxLayout *innerVbox = new WVBoxLayout(outerContainer);
  82.     WText *top = new WText("This is the top line");
  83.     innerVbox->addWidget(top, 0, AlignTop | AlignJustify);
  84.    
  85.     WContainerWidget *scrolledContainer = new WContainerWidget(); // no parent
  86.     scrolledContainer->setStyleClass("scrolledContainer");
  87.     // TODO - why don't scrollbars resize with window?
  88.     scrolledContainer->setOverflow(WContainerWidget::OverflowAuto, Horizontal);
  89.     scrolledContainer->setOverflow(WContainerWidget::OverflowAuto, Vertical);
  90.  
  91.     WVBoxLayout *vbox2 = new WVBoxLayout(scrolledContainer);
  92.     // create all widgets in a tab selection
  93.  
  94.     vbox2->addWidget( createTabs(), 0, ALIGN_TOP_CENTER);
  95.     innerVbox->addWidget(scrolledContainer, 1, ALIGN_TOP_CENTER);
  96.     WPanel *panel1 = new WPanel();
  97.     WContainerWidget *cw = new WContainerWidget();
  98.  
  99.     WHBoxLayout *logScanLayout = new WHBoxLayout(cw);
  100.     logScanLayout->addWidget( showLog(), 1, ALIGN_TOP_LEFT);
  101.     logScanLayout->addWidget( showScanStatus(), 1, ALIGN_TOP_RIGHT);
  102.    
  103.     panel1->setCentralWidget(cw);
  104.     panel1->setTitle("Log & Scan Status");
  105.     panel1->setTitleBar(true);
  106.     panel1->setCollapsible(true);
  107.  
  108.     vbox2->addWidget(panel1, 0, ALIGN_TOP_CENTER);
  109. }
  110.  
  111. WWidget *LayoutDemo::showLog() {
  112.   WContainerWidget *container = new WContainerWidget();
  113.  
  114.   container->setOverflow(WContainerWidget::OverflowScroll);
  115.   container->setStyleClass("log-container");
  116.   return container;
  117.  
  118. }
  119. WWidget *LayoutDemo::showScanStatus( ) {
  120.   WContainerWidget *container = new WContainerWidget();
  121.   container->setOverflow(WContainerWidget::OverflowScroll);
  122.   container->setStyleClass("log-container");
  123.   return container;
  124. }
  125.  
  126.  
  127. LayoutDemo::~LayoutDemo()
  128. {
  129. }
  130.  
  131.  
  132. WContainerWidget *LayoutDemo::createATab(string label)
  133. {
  134.   WContainerWidget *cw = new WContainerWidget();
  135.   WHBoxLayout *contentsLayout = new WHBoxLayout();
  136.   cw->setStyleClass("editScanContainer");
  137.   cw->setLayout(contentsLayout);
  138.  
  139.   WVBoxLayout *scanSelVbox = new WVBoxLayout();
  140.   WText *head1 = new WText(label);
  141.   head1->setStyleClass("col_text");
  142.   scanSelVbox->addWidget(head1, 0, ALIGN_TITLE);
  143.   scanSelVbox->addWidget(new WText("xxx"));
  144.   scanSelVbox->addWidget(new WText("yyy"));
  145.   scanSelVbox->addWidget(new WText("zzz"));
  146.   contentsLayout->addLayout(scanSelVbox, 1, ALIGN_TOP_LEFT);
  147.   contentsLayout->addWidget(new WText("00000"), 0, ALIGN_TOP_LEFT);
  148.   contentsLayout->addWidget(new WText("11111"), 0, ALIGN_TOP_LEFT);
  149.   contentsLayout->addWidget(new WText("22222"), 0, ALIGN_TOP_LEFT);
  150.   contentsLayout->addWidget(new WText("33333"), 0, ALIGN_TOP_LEFT);
  151.  
  152.   return cw;
  153. }
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162. WTabWidget *LayoutDemo::createTabs()
  163. {
  164.   WTabWidget *tabWidget = new WTabWidget( );
  165.   tabWidget->setStyleClass("mainTab");
  166.   WContainerWidget *cw;
  167.   tabWidget->addTab(cw = createATab("Axx"), "A", WTabWidget::PreLoading);
  168.   tabWidget->addTab(cw = createATab("Bxx"), "B", WTabWidget::PreLoading);
  169.   tabWidget->addTab(cw = createATab("Cxx"), "C", WTabWidget::PreLoading);
  170.   tabWidget->addTab(cw = createATab("Dxx"), "D", WTabWidget::PreLoading);
  171.  
  172.  
  173.     return tabWidget;
  174. }
  175.  
  176.  
  177.  
  178.  
  179.  
  180. WApplication *createApplication(const WEnvironment& env)
  181. {
  182.     /*
  183.      * You could read information from the environment to decide whether
  184.      * the user has permission to start a new application
  185.      */
  186.     LayoutDemo *r = new LayoutDemo(env);
  187.     //    r->readConfiguration("/tmp/radar_ctl.txt");
  188.     return r;
  189. }
  190.  
  191. int main(int argc, char **argv)
  192. {
  193.     /*
  194.      * Your main method may set up some shared resources, but should then
  195.      * start the server application (FastCGI or httpd) that starts listening
  196.      * for requests, and handles all of the application life cycles.
  197.      *
  198.      * The last argument to WRun specifies the function that will instantiate
  199.      * new application objects. That function is executed when a new user surfs
  200.      * to the Wt application, and after the library has negotiated browser
  201.      * support. The function should return a newly instantiated application
  202.      * object.
  203.      */
  204.     return WRun(argc, argv, &createApplication);
  205. }
Advertisement
Add Comment
Please, Sign In to add comment