style/StyleExample.C

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2006 Koen Deforche, Kessel-Lo, Belgium.
00003  *
00004  * See the LICENSE file for terms of use.
00005  */
00006 
00007 #include <boost/lexical_cast.hpp>
00008 
00009 #include <WLineEdit>
00010 #include <WIntValidator>
00011 #include <WText>
00012 #include <WPushButton>
00013 #include <WApplication>
00014 #include <WBreak>
00015 
00016 #include "RoundedWidget.h"
00017 #include "StyleExample.h"
00018 
00019 char loremipsum[] = "Lorem ipsum dolor sit amet, consectetur adipisicing "
00020    "elit, sed do eiusmod tempor incididunt ut labore et "
00021    "dolore magna aliqua. Ut enim ad minim veniam, quis "
00022    "nostrud exercitation ullamco laboris nisi ut aliquip " 
00023    "ex ea commodo consequat. Duis aute irure dolor in "
00024    "reprehenderit in voluptate velit esse cillum dolore eu "
00025    "fugiat nulla pariatur. Excepteur sint occaecat cupidatat "
00026    "non proident, sunt in culpa qui officia deserunt mollit "
00027    "anim id est laborum.";
00028 
00029 StyleExample::StyleExample(WContainerWidget *parent)
00030   : WContainerWidget(parent)
00031 {
00032   w_ = new RoundedWidget(RoundedWidget::All, this);
00033 
00034   new WText(loremipsum, w_->contents());
00035   new WBreak(this);
00036 
00037   new WText("Color (rgb): ", this);
00038   r_ = createValidateLineEdit(w_->backgroundColor().red(), 0, 255);
00039   g_ = createValidateLineEdit(w_->backgroundColor().green(), 0, 255);
00040   b_ = createValidateLineEdit(w_->backgroundColor().blue(), 0, 255);
00041 
00042   new WBreak(this);
00043 
00044   new WText("Radius (px): ", this);
00045   radius_ = createValidateLineEdit(w_->cornerRadius(), 1, 500);
00046 
00047   new WBreak(this);
00048 
00049   WPushButton *p = new WPushButton("Update!", this);
00050   p->clicked.connect(SLOT(this, StyleExample::updateStyle));
00051 
00052   new WBreak(this);
00053 
00054   error_ = new WText("", this);
00055 }
00056 
00057 WLineEdit *StyleExample::createValidateLineEdit(int value, int min, int max)
00058 {
00059   WLineEdit *le = new WLineEdit(boost::lexical_cast<std::wstring>(value),
00060                                 this);
00061   le->setTextSize(3);
00062   le->setValidator(new WIntValidator(min, max));
00063 
00064   return le;
00065 }
00066 
00067 void StyleExample::updateStyle()
00068 {
00069   if ((r_->validate() != WValidator::Valid)
00070       || (g_->validate() != WValidator::Valid)
00071       || (b_->validate() != WValidator::Valid))
00072     error_->setText("Color components must be numbers between 0 and 255.");
00073   else if (radius_->validate() != WValidator::Valid)
00074     error_->setText("Radius must be between 1 and 500.");
00075   else {
00076     w_->setBackgroundColor(WColor(boost::lexical_cast<int>(r_->text()),
00077                                   boost::lexical_cast<int>(g_->text()),
00078                                   boost::lexical_cast<int>(b_->text())));
00079     w_->setCornerRadius(boost::lexical_cast<int>(radius_->text()));
00080     error_->setText("");
00081   }
00082 }
00083 
00084 WApplication *createApplication(const WEnvironment& env)
00085 {
00086   WApplication *app = new WApplication(env);
00087   app->setTitle("Style example");
00088 
00089   app->root()->addWidget(new StyleExample());
00090   return app;
00091 }
00092 
00093 int main(int argc, char **argv)
00094 {
00095    return WRun(argc, argv, &createApplication);
00096 }

Generated on Sun Jul 1 19:37:23 2007 for Wt by doxygen 1.4.7