Do not use direct widget access when drawing tabs and popup menus

pull/1/head
Timothy Pearson 12 years ago
parent 4983755f93
commit 7bcedaa797

@ -869,20 +869,15 @@ void dotNETstyle::drawControl(TQ_ControlElement element,
// TABS
// ----
case CE_TabBarTab: {
const TQTabBar *tb = (const TQTabBar *) widget;
bool cornerWidget = false;
TQTabBar::Shape tbs = tb->shape();
TQTabBar::Shape tbs = ceData.tabBarData.shape;
bool selected = flags & Style_Selected;
int x, x2, y, y2, w, h;
r.rect(&x, &y, &w, &h);
r.coords(&x, &y, &x2, &y2);
if (tb->parent()->inherits(TQTABWIDGET_OBJECT_NAME_STRING)) {
const TQTabWidget *tw = (const TQTabWidget *)tb->parent();
TQWidget *cw = tw->cornerWidget(TQt::TopLeft);
if (cw) {
cornerWidget = true;
}
if (!ceData.tabBarData.cornerWidgets[TQStyleControlElementTabBarData::CWL_TopLeft].widgetObjectTypes.isEmpty()) {
cornerWidget = true;
}
switch (tbs) {
@ -1200,7 +1195,6 @@ void dotNETstyle::drawControl(TQ_ControlElement element,
return;
}
const TQPopupMenu *pum = (const TQPopupMenu *) widget;
static const int itemFrame = 2;
static const int itemHMargin = 3;
static const int itemVMargin = 3;
@ -1215,13 +1209,13 @@ void dotNETstyle::drawControl(TQ_ControlElement element,
bool active = flags & Style_Active;
bool disabled = !mi->isEnabled();
bool checkable = pum->isCheckable();
bool checkable = (elementFlags & CEF_IsCheckable);
int xpos = x;
int xm = itemFrame + checkcol + itemHMargin;
if (pum->erasePixmap() && !pum->erasePixmap()->isNull()) {
p->drawPixmap( x, y, *pum->erasePixmap(), x, y, w, h );
if (!ceData.bgPixmap.isNull()) {
p->drawPixmap( x, y, ceData.bgPixmap, x, y, w, h );
} else {
if (!TQApplication::reverseLayout()) {
p->fillRect( x, y, 22, h, cg.mid() );
@ -1814,18 +1808,16 @@ int dotNETstyle::pixelMetric(PixelMetric m, TQStyleControlElementData ceData, Co
// TABS
// ----
case PM_TabBarTabVSpace: {
const TQTabBar * tb = (const TQTabBar *) widget;
if (tb->shape() == TQTabBar::RoundedAbove ||
tb->shape() == TQTabBar::RoundedBelow)
if (ceData.tabBarData.shape == TQTabBar::RoundedAbove ||
ceData.tabBarData.shape == TQTabBar::RoundedBelow)
return 12;
else
return 0;
}
case PM_TabBarTabOverlap: {
const TQTabBar* tb = (const TQTabBar*)widget;
if (tb->shape() != TQTabBar::RoundedAbove &&
tb->shape() != TQTabBar::RoundedBelow)
if (ceData.tabBarData.shape != TQTabBar::RoundedAbove &&
ceData.tabBarData.shape != TQTabBar::RoundedBelow)
return 3; // Leave standard size alone
else
return 1; // Change size for our tabs only

@ -82,7 +82,7 @@ static unsigned contrast = 110;
PhaseStyle::PhaseStyle()
: KStyle(FilledFrameWorkaround | AllowMenuTransparency,
ThreeButtonScrollBar), hover_(0), hovertab_(0),
ThreeButtonScrollBar),
gradients_(TQPixmap::defaultDepth() > 8), kicker_(false)
{
TQSettings settings;
@ -412,11 +412,11 @@ void PhaseStyle::drawPhasePanel(TQPainter *painter,
void PhaseStyle::drawPhaseTab(TQPainter *painter,
int x, int y, int w, int h,
const TQColorGroup &group,
const TQTabBar *bar,
TQStyleControlElementData ceData,
ControlElementFlags /*elementFlags*/,
const TQStyleOption &option,
SFlags flags) const
{
const TQTabWidget *tabwidget;
bool selected = (flags & Style_Selected);
bool edge; // tab is at edge of bar
const int x2 = x + w - 1;
@ -425,21 +425,18 @@ void PhaseStyle::drawPhaseTab(TQPainter *painter,
painter->save();
// what position is the tab?
if ((bar->count() == 1)
|| (bar->indexOf(option.tab()->identifier()) == 0)) {
if ((ceData.tabBarData.tabCount == 1)
|| (ceData.tabBarData.identIndexMap[option.tab()->identifier()] == 0)) {
edge = true;
} else {
edge = false;
}
switch (TQTabBar::Shape(bar->shape())) {
switch (TQTabBar::Shape(ceData.tabBarData.shape)) {
case TQTabBar::RoundedAbove:
case TQTabBar::TriangularAbove: {
// is there a corner widget?
tabwidget = ::tqqt_cast<TQTabWidget*>(bar->parent());
if (edge && tabwidget
&& tabwidget->cornerWidget(reverse_ ?
TQt::TopRight : TQt::TopLeft)) {
if (!ceData.tabBarData.cornerWidgets[reverse_ ? TQStyleControlElementTabBarData::CWL_TopRight : TQStyleControlElementTabBarData::CWL_TopLeft].widgetObjectTypes.isEmpty()) {
edge = false;
}
@ -515,10 +512,7 @@ void PhaseStyle::drawPhaseTab(TQPainter *painter,
case TQTabBar::RoundedBelow:
case TQTabBar::TriangularBelow: {
// is there a corner widget?
tabwidget = ::tqqt_cast<TQTabWidget*>(bar->parent());
if (edge && tabwidget
&& tabwidget->cornerWidget(reverse_ ?
TQt::BottomRight : TQt::BottomLeft)) {
if (!ceData.tabBarData.cornerWidgets[reverse_ ? TQStyleControlElementTabBarData::CWL_BottomRight : TQStyleControlElementTabBarData::CWL_BottomLeft].widgetObjectTypes.isEmpty()) {
edge = false;
}
@ -823,7 +817,7 @@ void PhaseStyle::drawPrimitive(TQ_PrimitiveElement element,
case PE_Splitter:
cx = x + w/2 - 2; cy = y + h/2 - 2;
painter->fillRect(rect,
(hover_ == painter->device())
(flags & Style_MouseOver)
? TQColor(group.background().light(contrast))
: group.background());
@ -1117,7 +1111,7 @@ void PhaseStyle::drawKStylePrimitive(KStylePrimitive element,
case KPE_SliderHandle: {
const TQSlider* slider = ::tqqt_cast<const TQSlider*>(widget);
if (slider) {
TQColor color = (widget==hover_)
TQColor color = (flags & Style_MouseOver)
? TQColor(group.button().light(contrast))
: group.button();
if (slider->orientation() ==Qt::Horizontal) {
@ -1176,13 +1170,13 @@ void PhaseStyle::drawControl(TQ_ControlElement element,
drawPhasePanel(painter, x, y, w, h, group, true,
&group.brush(TQColorGroup::Mid));
drawPhaseBevel(painter, x+bd, y+bd, w-bd*2, h-bd*2, group,
(widget==hover_)
(flags & Style_MouseOver)
? TQColor(group.button().light(contrast))
: group.button(),
false, false, false);
} else {
drawPhaseButton(painter, x, y, w, h, group,
(widget==hover_)
(flags & Style_MouseOver)
? TQColor(group.button().light(contrast))
: group.button(), depress);
}
@ -1342,8 +1336,7 @@ void PhaseStyle::drawControl(TQ_ControlElement element,
}
case CE_PopupMenuItem: {
const TQPopupMenu *popup = ::tqqt_cast<const TQPopupMenu*>(widget);
if (!popup) {
if (!ceData.widgetObjectTypes.contains(TQPOPUPMENU_OBJECT_NAME_STRING)) {
KStyle::drawControl(element, painter, ceData, elementFlags, rect, group,
flags, option, widget);
return;
@ -1357,7 +1350,7 @@ void PhaseStyle::drawControl(TQ_ControlElement element,
int tabwidth = option.tabWidth();
int checkwidth = option.maxIconWidth();
bool checkable = popup->isCheckable();
bool checkable = (elementFlags & CEF_IsCheckable);
bool etchtext = styleHint(SH_EtchDisabledText, ceData, elementFlags);
active = flags & Style_Active;
enabled = mi->isEnabled();
@ -1503,13 +1496,9 @@ void PhaseStyle::drawControl(TQ_ControlElement element,
}
case CE_TabBarTab: {
const TQTabBar* tab = ::tqqt_cast<const TQTabBar*>(widget);
if (tab) {
if ((widget == hover_) && (option.tab() == hovertab_)) {
flags |= Style_MouseOver;
}
if (ceData.widgetObjectTypes.contains(TQTABBAR_OBJECT_NAME_STRING)) {
// this guy can get complicated, we we do it elsewhere
drawPhaseTab(painter, x, y, w, h, group, tab, option,
drawPhaseTab(painter, x, y, w, h, group, ceData, elementFlags, option,
flags);
} else { // not a tabbar
KStyle::drawControl(element, painter, ceData, elementFlags, rect, group,
@ -1526,8 +1515,7 @@ void PhaseStyle::drawControl(TQ_ControlElement element,
}
case CE_ProgressBarContents: {
const TQProgressBar* pbar = ::tqqt_cast<const TQProgressBar*>(widget);
if (!pbar) {
if (!ceData.widgetObjectTypes.contains(TQPROGRESSBAR_OBJECT_NAME_STRING)) {
KStyle::drawControl(element, painter, ceData, elementFlags, rect, group,
flags, option, widget);
return;
@ -1537,15 +1525,15 @@ void PhaseStyle::drawControl(TQ_ControlElement element,
painter->setBrush(group.brush(TQColorGroup::Highlight));
painter->setPen(group.dark());
if (!pbar->totalSteps()) {
if (!ceData.totalSteps) {
// busy indicator
int bar = pixelMetric(PM_ProgressBarChunkWidth, ceData, elementFlags, widget) + 2;
int progress = pbar->progress() % ((w-bar) * 2);
int progress = ceData.currentStep % ((w-bar) * 2);
if (progress > (w-bar)) progress = 2 * (w-bar) - progress;
painter->drawRect(x+progress+1, y+1, bar-2, h-2);
} else {
double progress = static_cast<double>(pbar->progress()) /
static_cast<double>(pbar->totalSteps());
double progress = static_cast<double>(ceData.currentStep) /
static_cast<double>(ceData.totalSteps);
dx = static_cast<int>(w * progress);
if (dx < 4) break;
if (reverse_) x += w - dx;
@ -1657,7 +1645,7 @@ void PhaseStyle::drawComplexControl(TQ_ComplexControl control,
sunken = (active == SC_ComboBoxArrow);
drawPhaseButton(painter, x, y, w, h, group,
(widget==hover_)
(flags & Style_MouseOver)
? TQColor(group.button().light(contrast))
: group.button(), sunken);
@ -1818,7 +1806,7 @@ void PhaseStyle::drawComplexControl(TQ_ComplexControl control,
if (reverse_) subrect.moveLeft(spin->upRect().left());
drawPhaseBevel(painter, subrect.x(), subrect.y(),
subrect.width(), subrect.height(), group,
(widget==hover_)
(flags & Style_MouseOver)
? TQColor(group.button().light(contrast))
: group.button(), false, false, false);
}
@ -1995,8 +1983,8 @@ int PhaseStyle::pixelMetric(PixelMetric metric, TQStyleControlElementData ceData
return 24;
case PM_TabBarTabVSpace:
if (const TQTabBar *tb = ::tqqt_cast<const TQTabBar*>(widget)) {
if (tb->shape() == TQTabBar::RoundedAbove) {
if (ceData.widgetObjectTypes.contains(TQTABBAR_OBJECT_NAME_STRING)) {
if (ceData.tabBarData.shape == TQTabBar::RoundedAbove) {
return 10;
} else {
return 6;
@ -2186,8 +2174,7 @@ TQSize PhaseStyle::sizeFromContents(ContentsType contents,
case CT_PopupMenuItem: {
if (!widget || option.isDefault()) return contentsize;
const TQPopupMenu *popup = ::tqqt_cast<const TQPopupMenu*>(widget);
if (!popup) {
if (!ceData.widgetObjectTypes.contains(TQPOPUPMENU_OBJECT_NAME_STRING)) {
return KStyle::sizeFromContents(contents, ceData, elementFlags, contentsize,
option, widget);
}
@ -2208,7 +2195,7 @@ TQSize PhaseStyle::sizeFromContents(ContentsType contents,
h = TQMAX(h, item->pixmap()->height() + ITEMFRAME*2);
} else {
h = TQMAX(h, MINICONSIZE + ITEMFRAME*2);
h = TQMAX(h, popup->fontMetrics().height()
h = TQMAX(h, TQFontMetrics(ceData.font).height()
+ ITEMVMARGIN*2 + ITEMFRAME*2);
}
if (item->iconSet())
@ -2222,7 +2209,7 @@ TQSize PhaseStyle::sizeFromContents(ContentsType contents,
else if (item->popup())
w += 2 * ARROWMARGIN;
if (option.maxIconWidth() || popup->isCheckable()) {
if (option.maxIconWidth() || (elementFlags & CEF_IsCheckable)) {
w += TQMAX(option.maxIconWidth(),
TQIconSet::iconSize(TQIconSet::Small).width())
+ ITEMHMARGIN*2;
@ -2373,54 +2360,6 @@ bool PhaseStyle::objectEventHandler( TQStyleControlElementData ceData, ControlEl
}
}
} else if (highlights_) { // "mouseover" events
if (::tqqt_cast<TQPushButton*>(object) ||
::tqqt_cast<TQComboBox*>(object) ||
::tqqt_cast<TQSpinWidget*>(object) ||
::tqqt_cast<TQCheckBox*>(object) ||
::tqqt_cast<TQRadioButton*>(object) ||
::tqqt_cast<TQSlider*>(object) ||
object->inherits(TQSPLITTERHANDLE)) {
if (event->type() == TQEvent::Enter) {
if (0 != (widget = ::tqqt_cast<TQWidget*>(object)) &&
widget->isEnabled()) {
hover_ = widget;
widget->repaint(false);
}
} else if (event->type() == TQEvent::Leave) {
if (0 != (widget = ::tqqt_cast<TQWidget*>(object))) {
hover_ = 0;
widget->repaint(false);
}
}
} else if (::tqqt_cast<TQTabBar*>(object)) { // special case for qtabbar
if (event->type() == TQEvent::Enter) {
if (0 != (widget = ::tqqt_cast<TQWidget*>(object)) &&
widget->isEnabled()) {
hover_ = widget;
hovertab_ = 0;;
widget->repaint(false);
}
} else if (event->type() == TQEvent::Leave) {
if (0 != (widget = ::tqqt_cast<TQWidget*>(object))) {
hover_ = 0;
hovertab_ = 0;;
widget->repaint(false);
}
} else if (event->type() == TQEvent::MouseMove) {
TQTabBar *tabbar;
if (0 != (tabbar = ::tqqt_cast<TQTabBar*>(object))) {
TQMouseEvent *me;
if (0 != (me = dynamic_cast<TQMouseEvent*>(event))) {
TQTab *tab = tabbar->selectTab(me->pos());
if (hovertab_ != tab) {
hovertab_ = tab;
tabbar->repaint(false);
}
}
}
}
}
}
}

@ -170,8 +170,9 @@ private:
void drawPhaseTab(TQPainter *painter,
int x, int y, int w, int h,
const TQColorGroup &group,
const TQTabBar *bar,
const TQStyleOption &option,
TQStyleControlElementData ceData,
ControlElementFlags elementFlags,
const TQStyleOption &option,
const SFlags flags) const;
void drawPhaseGradient(TQPainter *painter,
@ -187,8 +188,6 @@ private:
bool objectEventHandler( TQStyleControlElementData ceData, ControlElementFlags elementFlags, void* source, TQEvent *e );
private:
TQWidget *hover_;
TQTab *hovertab_;
TQMap<unsigned int, TQIntDict<GradientSet> > * gradients;
bool gradients_;
bool highlights_;

Loading…
Cancel
Save