/usr/lib/Wt/examples/style/RoundedWidget.C is in witty-examples 3.3.0-1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | /*
* Copyright (C) 2008 Emweb bvba, Kessel-Lo, Belgium.
*
* See the LICENSE file for terms of use.
*/
#include <Wt/WCssDecorationStyle>
#include <Wt/WContainerWidget>
#include <Wt/WImage>
#include "RoundedWidget.h"
#include "CornerImage.h"
RoundedWidget::RoundedWidget(int corners, WContainerWidget *parent)
: WCompositeWidget(parent),
backgroundColor_(WColor(0xD4,0xDD,0xFF)),
surroundingColor_(WColor(0xFF,0xFF,0xFF)),
radius_(10),
corners_(corners)
{
setImplementation(impl_ = new WContainerWidget());
contents_ = new WContainerWidget(impl_);
create();
}
RoundedWidget::~RoundedWidget()
{
if (images_[1])
delete images_[1];
if (images_[3])
delete images_[3];
}
void RoundedWidget::create()
{
if (corners_ & TopLeft) {
images_[0] = new CornerImage(CornerImage::TopLeft, backgroundColor_,
surroundingColor_, radius_);
images_[0]->setPositionScheme(Absolute);
images_[0]->setMargin(0);
} else
images_[0] = 0;
if (corners_ & TopRight)
images_[1] = new CornerImage(CornerImage::TopRight, backgroundColor_,
surroundingColor_, radius_);
else
images_[1] = 0;
if (corners_ & BottomLeft) {
images_[2] = new CornerImage(CornerImage::BottomLeft, backgroundColor_,
surroundingColor_, radius_);
images_[2]->setPositionScheme(Absolute);
images_[2]->setMargin(0);
} else
images_[2] = 0;
if (corners_ & BottomRight)
images_[3] = new CornerImage(CornerImage::BottomRight, backgroundColor_,
surroundingColor_, radius_);
else
images_[3] = 0;
/*
* At the top: an image (top left corner) inside
* a container widget with background image top right.
*/
top_ = new WContainerWidget();
top_->resize(WLength::Auto, radius_);
top_->setPositionScheme(Relative);
if (images_[1])
top_->decorationStyle().setBackgroundImage(images_[1]->imageRef(),
WCssDecorationStyle::NoRepeat,
Top | Right);
if (images_[0])
top_->addWidget(images_[0]);
impl_->insertBefore(top_, contents_); // insert top before the contents
/*
* At the bottom: an image (bottom left corner) inside
* a container widget with background image bottom right.
*/
bottom_ = new WContainerWidget();
bottom_->setPositionScheme(Relative);
bottom_->resize(WLength::Auto, radius_);
if (images_[3])
bottom_->decorationStyle().setBackgroundImage(images_[3]->imageRef(),
WCssDecorationStyle::NoRepeat,
Bottom | Right);
if (images_[2])
bottom_->addWidget(images_[2]);
impl_->addWidget(bottom_);
decorationStyle().setBackgroundColor(backgroundColor_);
contents_->setMargin(WLength(radius_), Left | Right);
}
void RoundedWidget::setBackgroundColor(WColor color)
{
backgroundColor_ = color;
adjust();
}
void RoundedWidget::setSurroundingColor(WColor color)
{
surroundingColor_ = color;
adjust();
}
void RoundedWidget::setCornerRadius(int radius)
{
radius_ = radius;
adjust();
}
void RoundedWidget::enableRoundedCorners(bool how)
{
if (images_[0]) images_[0]->setHidden(!how);
if (images_[2]) images_[2]->setHidden(!how);
if (images_[1]) {
images_[1]->setHidden(!how);
if (!how)
top_->decorationStyle().setBackgroundImage("");
else
top_->decorationStyle()
.setBackgroundImage(images_[1]->imageRef(),
WCssDecorationStyle::NoRepeat,
Top | Right);
}
if (images_[3]) {
images_[3]->setHidden(!how);
if (!how)
bottom_->decorationStyle().setBackgroundImage("");
else
bottom_->decorationStyle()
.setBackgroundImage(images_[3]->imageRef(),
WCssDecorationStyle::NoRepeat,
Top | Right);
}
}
void RoundedWidget::adjust()
{
if (images_[0] && !images_[0]->isHidden()) images_[0]->setRadius(radius_);
if (images_[1] && !images_[1]->isHidden()) images_[1]->setRadius(radius_);
if (images_[2] && !images_[2]->isHidden()) images_[2]->setRadius(radius_);
if (images_[3] && !images_[3]->isHidden()) images_[3]->setRadius(radius_);
if (images_[0] && !images_[0]->isHidden())
images_[0]->setForeground(backgroundColor_);
if (images_[1] && !images_[1]->isHidden())
images_[1]->setForeground(backgroundColor_);
if (images_[2] && !images_[2]->isHidden())
images_[2]->setForeground(backgroundColor_);
if (images_[3] && !images_[3]->isHidden())
images_[3]->setForeground(backgroundColor_);
if (images_[1])
top_->decorationStyle().setBackgroundImage(images_[1]->imageRef(),
WCssDecorationStyle::NoRepeat,
Top | Right);
if (images_[3])
bottom_->decorationStyle().setBackgroundImage(images_[3]->imageRef(),
WCssDecorationStyle::NoRepeat,
Bottom | Right);
top_->resize(WLength::Auto, radius_);
bottom_->resize(WLength::Auto, radius_);
contents_->setMargin(radius_, Left | Right);
decorationStyle().setBackgroundColor(backgroundColor_);
}
|