Browse Source

Repair menu icon handling

Various control and primitive fixes
r14.0.x
Timothy Pearson 10 years ago
parent
commit
d4b531e2cc
  1. 292
      plugin/simplestyle.cpp
  2. 15
      plugin/simplestyle.h

292
plugin/simplestyle.cpp

@ -56,6 +56,7 @@
#include <kcmdlineargs.h>
#include <kaboutdata.h>
#include <kicontheme.h>
#include <kiconloader.h>
#endif
#define DEBUG_WARNINGS 1
@ -125,50 +126,67 @@ inline TQString convertQt4ToTQt3String(QString qt4string)
return TQString::fromUtf8(qt4string.toUtf8().data());
}
inline TQIconSet convertQt4ToTQt3IconSet(QIcon qt4icon)
inline TQIconSet convertQt4ToTQt3IconSet(QIcon qt4icon, int smallsize, int largesize)
{
int i=0;
int j=0;
int k=0;
QIcon::Mode qt4iconmode;
TQIconSet::Mode tqt3iconmode;
QIcon::State qt4iconstate;
TQIconSet::State tqt3iconstate;
TQIconSet::Size tqt3iconsize;
TQSize tqt3iconsized;
TQIconSet tqt3iconset;
// Get the maximum icon size stored in the QIcon and generate a pixmap of that size
QSize qt4size = qt4icon.actualSize(QSize(32768,32768));
// Generate all required sizes of icon from the TQt3 settings
TQSize smallIconSize(smallsize, smallsize);
TQSize largeIconSize(largesize, largesize);
for (i=0;i<3;i++) {
for (j=0;j<2;j++) {
if (i==0) {
qt4iconmode = QIcon::Normal;
tqt3iconmode = TQIconSet::Normal;
}
if (i==1) {
qt4iconmode = QIcon::Disabled;
tqt3iconmode = TQIconSet::Disabled;
}
if (i==2) {
qt4iconmode = QIcon::Active;
tqt3iconmode = TQIconSet::Active;
}
if (j==0) {
qt4iconstate = QIcon::On;
tqt3iconstate = TQIconSet::On;
}
if (j==1) {
qt4iconstate = QIcon::Off;
tqt3iconstate = TQIconSet::Off;
for (k=0;k<2;k++) {
if (i==0) {
qt4iconmode = QIcon::Normal;
tqt3iconmode = TQIconSet::Normal;
}
if (i==1) {
qt4iconmode = QIcon::Disabled;
tqt3iconmode = TQIconSet::Disabled;
}
if (i==2) {
qt4iconmode = QIcon::Active;
tqt3iconmode = TQIconSet::Active;
}
if (j==0) {
qt4iconstate = QIcon::On;
tqt3iconstate = TQIconSet::On;
}
if (j==1) {
qt4iconstate = QIcon::Off;
tqt3iconstate = TQIconSet::Off;
}
if (k==0) {
tqt3iconsize = TQIconSet::Small;
tqt3iconsized = smallIconSize;
}
if (k==1) {
tqt3iconsize = TQIconSet::Large;
tqt3iconsized = largeIconSize;
}
QPixmap qt4iconpm = qt4icon.pixmap(QSize(tqt3iconsized.width(), tqt3iconsized.height()), qt4iconmode, qt4iconstate);
TQPixmap tqtPM(qt4iconpm.width(), qt4iconpm.height(), qt4iconpm.depth());
QPixmap qtPM = QPixmap::fromX11Pixmap(tqtPM.handle(), QPixmap::ExplicitlyShared);
qtPM.fill(Qt::transparent);
QPainter qt4painter(&qtPM);
qt4painter.drawPixmap(0, 0, qt4iconpm);
qt4painter.end();
tqt3iconset.setPixmap(tqtPM, tqt3iconsize, tqt3iconmode, tqt3iconstate);
}
QPixmap qt4iconpm = qt4icon.pixmap(qt4size, qt4iconmode, qt4iconstate);
TQPixmap tqtPM(qt4iconpm.width(), qt4iconpm.height(), qt4iconpm.depth());
QPixmap qtPM = QPixmap::fromX11Pixmap(tqtPM.handle(), QPixmap::ExplicitlyShared);
QPainter qt4painter(&qtPM);
qt4painter.drawPixmap(0, 0, qt4iconpm);
qt4painter.end();
tqt3iconset.setPixmap(tqtPM, TQIconSet::Automatic, tqt3iconmode, tqt3iconstate);
}
}
@ -183,6 +201,8 @@ inline TQPixmap convertQt4ToTQt3Pixmap(QIcon qt4icon)
QPixmap qt4iconpm = qt4icon.pixmap(qt4size);
TQPixmap tqtPM(qt4iconpm.width(), qt4iconpm.height(), qt4iconpm.depth());
QPixmap qtPM = QPixmap::fromX11Pixmap(tqtPM.handle(), QPixmap::ExplicitlyShared);
qtPM.fill(Qt::transparent);
QPainter qt4painter(&qtPM);
qt4painter.drawPixmap(0, 0, qt4iconpm);
qt4painter.end();
@ -561,7 +581,7 @@ inline TQStyle::SFlags convertQt4ToTQt3SFlags(QStyle::State qt4stateflags, TQt3W
}
#define NO_QT3_EQUIVALENT can_override = false;
#define DO_NOT_DRAW can_override = false; do_not_draw = true;
#define DO_NOT_DRAW can_override = true; do_not_draw = true;
SimpleStyle::SimpleStyle()
{
@ -588,12 +608,50 @@ SimpleStyle::SimpleStyle()
// Set the Qt4 icon set to the TDE icon set
QIcon::setThemeName(convertTQt3ToQt4String(KIconTheme::current()));
// Set up Qt4 size hints to match the TDE sizes
// FIXME
// m_tqt3IconSize_MenuItem and m_tqt3IconSize_Large are still hardcoded
// Verify all mappings
m_tqt3IconSize_NoGroup = IconSize(KIcon::NoGroup);
m_tqt3IconSize_Desktop = IconSize(KIcon::Desktop);
m_tqt3IconSize_FirstGroup = IconSize(KIcon::FirstGroup);
m_tqt3IconSize_Toolbar = IconSize(KIcon::Toolbar);
m_tqt3IconSize_MainToolbar = IconSize(KIcon::MainToolbar);
m_tqt3IconSize_Small = IconSize(KIcon::Small);
m_tqt3IconSize_Large = 32;
m_tqt3IconSize_Panel = IconSize(KIcon::Panel);
m_tqt3IconSize_LastGroup = IconSize(KIcon::LastGroup);
m_tqt3IconSize_User = IconSize(KIcon::User);
m_tqt3IconSize_MenuItem = 16;
m_tqt3IconSize_Tabbar = m_tqt3IconSize_MenuItem;
m_tqt3IconSize_Listview = m_tqt3IconSize_MenuItem;
m_tqt3IconSize_Button = m_tqt3IconSize_MenuItem;
#else // INTEGRATE_WITH_TDE
if (!tqApp) {
// Qt4 can be SO STUPID sometimes...why can't I get the X11 display directly from qApp?!?!??
QWidget myhackedwidget;
new TQApplication(myhackedwidget.x11Info().display());
}
// Set up Qt4 size hints to match the hardcoded TQt3 sizes
// FIXME
// Verify all mappings
m_tqt3IconSize_NoGroup = 32;
m_tqt3IconSize_Desktop = 32;
m_tqt3IconSize_FirstGroup = m_tqt3IconSize_NoGroup;
m_tqt3IconSize_Toolbar = 22;
m_tqt3IconSize_MainToolbar = 22;
m_tqt3IconSize_Small = 22; // Hardcoded in TQt3 qiconset.cpp:56
m_tqt3IconSize_Large = 32; // Hardcoded in TQt3 qiconset.cpp:56
m_tqt3IconSize_Panel = 22;
m_tqt3IconSize_LastGroup = m_tqt3IconSize_NoGroup;
m_tqt3IconSize_User = m_tqt3IconSize_NoGroup;
m_tqt3IconSize_MenuItem = 16;
m_tqt3IconSize_Tabbar = m_tqt3IconSize_MenuItem;
m_tqt3IconSize_Listview = m_tqt3IconSize_MenuItem;
m_tqt3IconSize_Button = m_tqt3IconSize_MenuItem;
#endif // INTEGRATE_WITH_TDE
// Set the Qt4 palette to the TQt3 palette
@ -998,20 +1056,40 @@ int SimpleStyle::pixelMetric(PixelMetric metric, const QStyleOption *opt, const
tqt3pixelmetric = TQStyle::PM_HeaderMargin;
retswitch = 1;
break;
// case QStyle::PM_SpinBoxSliderHeight:
// tqt3pixelmetric = TQStyle::PM_SpinBoxSliderHeight;
// retswitch = 1;
// break;
// case QStyle::PM_ToolBarIconSize:
// tqt3pixelmetric = TQStyle::PM_ToolBarIconSize;
// retswitch = 1;
// break;
// case QStyle::PM_SmallIconSize:
// tqt3pixelmetric = TQStyle::PM_SmallIconSize;
case QStyle::PM_ToolBarIconSize:
retval = m_tqt3IconSize_Toolbar;
retswitch = 2;
break;
case QStyle::PM_SmallIconSize:
retval = m_tqt3IconSize_Small;
retswitch = 2;
break;
case QStyle::PM_LargeIconSize:
retval = m_tqt3IconSize_Large;
retswitch = 2;
break;
case QStyle::PM_TabBarIconSize:
retval = m_tqt3IconSize_Tabbar;
retswitch = 2;
break;
case QStyle::PM_IconViewIconSize:
retval = m_tqt3IconSize_Desktop;
retswitch = 2;
break;
case QStyle::PM_ListViewIconSize:
retval = m_tqt3IconSize_Listview;
retswitch = 2;
break;
case QStyle::PM_ButtonIconSize:
retval = m_tqt3IconSize_Button;
retswitch = 2;
break;
// case QStyle::PM_MessageBoxIconSize:
// tqt3pixelmetric = TQStyle::PM_MessageBoxIconSize;
// retswitch = 1;
// break;
// case QStyle::PM_LargeIconSize:
// tqt3pixelmetric = TQStyle::PM_LargeIconSize;
// case QStyle::PM_SpinBoxSliderHeight:
// tqt3pixelmetric = TQStyle::PM_SpinBoxSliderHeight;
// retswitch = 1;
// break;
// case QStyle::PM_FocusFrameHMargin:
@ -1022,14 +1100,6 @@ int SimpleStyle::pixelMetric(PixelMetric metric, const QStyleOption *opt, const
// tqt3pixelmetric = TQStyle::PM_FocusFrameVMargin;
// retswitch = 1;
// break;
// case QStyle::PM_IconViewIconSize:
// tqt3pixelmetric = TQStyle::PM_IconViewIconSize;
// retswitch = 1;
// break;
// case QStyle::PM_ListViewIconSize:
// tqt3pixelmetric = TQStyle::PM_ListViewIconSize;
// retswitch = 1;
// break;
// case QStyle::PM_ToolTipLabelFrameWidth:
// tqt3pixelmetric = TQStyle::PM_ToolTipLabelFrameWidth;
// retswitch = 1;
@ -1042,22 +1112,10 @@ int SimpleStyle::pixelMetric(PixelMetric metric, const QStyleOption *opt, const
// tqt3pixelmetric = TQStyle::PM_RadioButtonLabelSpacing;
// retswitch = 1;
// break;
// case QStyle::PM_TabBarIconSize:
// tqt3pixelmetric = TQStyle::PM_TabBarIconSize;
// retswitch = 1;
// break;
// case QStyle::PM_SizeGripSize:
// tqt3pixelmetric = TQStyle::PM_SizeGripSize;
// retswitch = 1;
// break;
// case QStyle::PM_MessageBoxIconSize:
// tqt3pixelmetric = TQStyle::PM_MessageBoxIconSize;
// retswitch = 1;
// break;
// case QStyle::PM_ButtonIconSize:
// tqt3pixelmetric = TQStyle::PM_ButtonIconSize;
// retswitch = 1;
// break;
// case QStyle::PM_TextCursorWidth:
// tqt3pixelmetric = TQStyle::PM_TextCursorWidth;
// retswitch = 1;
@ -1162,7 +1220,7 @@ TQWidget* SimpleStyle::initializeInterfaceWidget(TQt3WidgetType wt, const QWidge
newTab->setIdentifier(i);
}
else {
TQTab* newTab = new TQTab(convertQt4ToTQt3IconSet(qt4tabbar_widget->tabIcon(i)), convertQt4ToTQt3String(qt4tabbar_widget->tabText(i)));
TQTab* newTab = new TQTab(convertQt4ToTQt3IconSet(qt4tabbar_widget->tabIcon(i), m_tqt3IconSize_Small, m_tqt3IconSize_Large), convertQt4ToTQt3String(qt4tabbar_widget->tabText(i)));
m_tqt3tabbar_widget->insertTab(newTab, i);
newTab->setIdentifier(i);
}
@ -1248,7 +1306,7 @@ TQWidget* SimpleStyle::initializeInterfaceWidget(TQt3WidgetType wt, const QWidge
m_tqt3popupmenu_widget->insertItem(convertQt4ToTQt3String(currentAction->text()), i, i);
}
else {
m_tqt3popupmenu_widget->insertItem(convertQt4ToTQt3IconSet(currentAction->icon()), convertQt4ToTQt3String(currentAction->text()), i, i);
m_tqt3popupmenu_widget->insertItem(convertQt4ToTQt3IconSet(currentAction->icon(), m_tqt3IconSize_Small, m_tqt3IconSize_Large), convertQt4ToTQt3String(currentAction->text()), i, i);
}
// FIXME
// Handle pixmaps, etc.
@ -1284,7 +1342,7 @@ TQWidget* SimpleStyle::initializeInterfaceWidget(TQt3WidgetType wt, const QWidge
m_tqt3menubar_widget->insertItem(convertQt4ToTQt3String(currentAction->text()), i, i);
}
else {
m_tqt3menubar_widget->insertItem(convertQt4ToTQt3IconSet(currentAction->icon()), convertQt4ToTQt3String(currentAction->text()), i, i);
m_tqt3menubar_widget->insertItem(convertQt4ToTQt3IconSet(currentAction->icon(), m_tqt3IconSize_Small, m_tqt3IconSize_Large), convertQt4ToTQt3String(currentAction->text()), i, i);
}
// FIXME
// Handle pixmaps, etc.
@ -1678,6 +1736,7 @@ void SimpleStyle::drawControl(ControlElement element, const QStyleOption *opt, Q
TQStyle::SFlags sflags = 0;
bool can_override = true;
bool do_not_draw = false;
TQStyle::ControlElement tqtCE;
bool draw_second_element = false;
@ -1853,12 +1912,26 @@ void SimpleStyle::drawControl(ControlElement element, const QStyleOption *opt, Q
}
}
break;
case QStyle::CE_ToolBar:
// TQt3 treats this as a primitive
// It is drawn as such below
DO_NOT_DRAW
break;
case QStyle::CE_HeaderSection:
// TQt3 treats this as a primitive
// It is drawn as such below
DO_NOT_DRAW
break;
case QStyle::CE_MenuBarEmptyArea:
tqtCE = TQStyle::CE_MenuBarEmptyArea;
break;
case QStyle::CE_MenuEmptyArea:
tqtCE = TQStyle::CE_MenuBarEmptyArea;
break;
case QStyle::CE_ItemViewItem:
// Ignore request as Qt3 has no equivalent
can_override = false;
break;
case QStyle::CE_ShapedFrame:
// Ignore request as Qt3 has no equivalent
can_override = false;
@ -1914,15 +1987,25 @@ void SimpleStyle::drawControl(ControlElement element, const QStyleOption *opt, Q
tqtPainter.fillRect(TQRect(tqt3elementrect.x()+tqt3tabwidth, tqt3elementrect.y(), tqt3elementrect.width()-(tqt3tabwidth*2), tqt3elementrect.height()), tqt3colorgroup.background());
}
// Instruct TQt3 to draw the control
// FIXME
// Implement sflags and QStyleOption
tqApp->style().drawControl(tqtCE, &tqtPainter, interfaceWidget, tqt3elementrect, tqt3colorgroup, sflags, tqt3opt);
if (draw_second_element == true) {
tqApp->style().drawControl(tqtCE_element2, &tqtPainter, interfaceWidget, tqt3element2rect, tqt3colorgroup, sflags, tqt3opt_element2);
if (element == QStyle::CE_ToolBar) {
tqApp->style().drawPrimitive(TQStyle::PE_PanelDockWindow, &tqtPainter, tqt3elementrect, tqt3colorgroup, sflags, tqt3opt);
}
if (draw_third_element == true) {
tqApp->style().drawControl(tqtCE_element3, &tqtPainter, interfaceWidget, tqt3element3rect, tqt3colorgroup, sflags, tqt3opt_element3);
if (element == QStyle::CE_HeaderSection) {
tqApp->style().drawPrimitive(TQStyle::PE_HeaderSection, &tqtPainter, tqt3elementrect, tqt3colorgroup, sflags, tqt3opt);
}
if (do_not_draw == false) {
// Instruct TQt3 to draw the control
// FIXME
// Implement sflags and QStyleOption
tqApp->style().drawControl(tqtCE, &tqtPainter, interfaceWidget, tqt3elementrect, tqt3colorgroup, sflags, tqt3opt);
if (draw_second_element == true) {
tqApp->style().drawControl(tqtCE_element2, &tqtPainter, interfaceWidget, tqt3element2rect, tqt3colorgroup, sflags, tqt3opt_element2);
}
if (draw_third_element == true) {
tqApp->style().drawControl(tqtCE_element3, &tqtPainter, interfaceWidget, tqt3element3rect, tqt3colorgroup, sflags, tqt3opt_element3);
}
}
tqtPainter.end();
@ -1934,8 +2017,10 @@ void SimpleStyle::drawControl(ControlElement element, const QStyleOption *opt, Q
#endif
}
else {
// Tell Qt4 to draw it
QCommonStyle::drawControl(element, opt, p, w);
if (do_not_draw == false) {
// Tell Qt4 to draw it
QCommonStyle::drawControl(element, opt, p, w);
}
}
}
@ -1974,6 +2059,10 @@ void SimpleStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QP
tqtPE = TQStyle::PE_PanelPopup;
tqt3opt = TQStyleOption(static_cast<const QStyleOptionFrame*>(opt)->lineWidth, static_cast<const QStyleOptionFrame*>(opt)->midLineWidth);
break;
case QStyle::PE_PanelToolBar:
tqtPE = TQStyle::PE_PanelDockWindow;
tqt3opt = TQStyleOption(static_cast<const QStyleOptionFrame*>(opt)->lineWidth, static_cast<const QStyleOptionFrame*>(opt)->midLineWidth);
break;
case QStyle::PE_PanelButtonBevel:
tqtPE = TQStyle::PE_ButtonBevel;
break;
@ -1991,14 +2080,55 @@ void SimpleStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QP
tqt3opt = TQStyleOption(static_cast<const QStyleOptionFrame*>(opt)->lineWidth, static_cast<const QStyleOptionFrame*>(opt)->midLineWidth);
break;
case QStyle::PE_FrameFocusRect:
tqtPE = TQStyle::PE_FocusRect;
// HACK
// Qt4 tries to draw a focus rectangle around the entire tab
// Needless to say this is ugly
// TQt3 tries to draw the focus rectangle around the tab text only, which is better
if (dynamic_cast<const QTabBar*>(w)) {
// FIXME
// We should attempt to draw the focus rectangle around the tab's text instead
DO_NOT_DRAW
}
else {
tqtPE = TQStyle::PE_FocusRect;
}
break;
case QStyle::PE_FrameButtonTool:
tqtPE = TQStyle::PE_ButtonTool;
break;
case QStyle::PE_IndicatorToolBarHandle:
tqtPE = TQStyle::PE_DockWindowHandle;
break;
case QStyle::PE_IndicatorToolBarSeparator:
tqtPE = TQStyle::PE_DockWindowSeparator;
break;
case QStyle::PE_IndicatorDockWidgetResizeHandle:
tqtPE = TQStyle::PE_DockWindowResizeHandle;
break;
case QStyle::PE_IndicatorMenuCheckMark:
tqtPE = TQStyle::PE_Indicator;
break;
case QStyle::PE_PanelTipLabel:
NO_QT3_EQUIVALENT
break;
case QStyle::PE_PanelItemViewItem:
NO_QT3_EQUIVALENT
break;
case QStyle::PE_PanelItemViewRow:
NO_QT3_EQUIVALENT
break;
case QStyle::PE_PanelScrollAreaCorner:
NO_QT3_EQUIVALENT
break;
case QStyle::PE_FrameTabBarBase:
NO_QT3_EQUIVALENT
break;
case QStyle::PE_IndicatorBranch:
NO_QT3_EQUIVALENT
break;
case QStyle::PE_IndicatorHeaderArrow:
tqtPE = TQStyle::PE_HeaderArrow;
break;
case QStyle::PE_FrameTabWidget:
tqtPE = TQStyle::PE_PanelTabWidget;
// HACK
@ -2113,9 +2243,11 @@ void SimpleStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QP
}
}
// Instruct TQt3 to draw the primitive
if (!((tqtPE == TQStyle::PE_PanelLineEdit) && (draw_transparent_background == true))) {
tqApp->style().drawPrimitive(tqtPE, &tqtPainter, tqt3paintrect, tqt3colorgroup, sflags, tqt3opt);
if (do_not_draw == false) {
// Instruct TQt3 to draw the primitive
if (!((tqtPE == TQStyle::PE_PanelLineEdit) && (draw_transparent_background == true))) {
tqApp->style().drawPrimitive(tqtPE, &tqtPainter, tqt3paintrect, tqt3colorgroup, sflags, tqt3opt);
}
}
tqtPainter.end();

15
plugin/simplestyle.h

@ -90,6 +90,21 @@ private:
TQWidget* m_tqt3window_widget;
TQTitleBar* m_tqt3titlebar_widget;
TQMenuBar* m_tqt3menubar_widget;
int m_tqt3IconSize_NoGroup;
int m_tqt3IconSize_Desktop;
int m_tqt3IconSize_FirstGroup;
int m_tqt3IconSize_Toolbar;
int m_tqt3IconSize_Tabbar;
int m_tqt3IconSize_MainToolbar;
int m_tqt3IconSize_Small;
int m_tqt3IconSize_Panel;
int m_tqt3IconSize_LastGroup;
int m_tqt3IconSize_User;
int m_tqt3IconSize_MenuItem;
int m_tqt3IconSize_Large;
int m_tqt3IconSize_Listview;
int m_tqt3IconSize_Button;
};
#endif
Loading…
Cancel
Save