| 54 |
|
|
| 55 |
#include <X11/Xlib.h> |
#include <X11/Xlib.h> |
| 56 |
|
|
| 57 |
|
#define ICON_MARGIN 1 |
| 58 |
|
|
| 59 |
extern "C" |
extern "C" |
| 60 |
{ |
{ |
| 61 |
KDE_EXPORT KPanelApplet* init(QWidget *parent, const QString& configFile) |
KDE_EXPORT KPanelApplet* init(QWidget *parent, const QString& configFile) |
| 461 |
delete emb; |
delete emb; |
| 462 |
return; |
return; |
| 463 |
} |
} |
| 464 |
|
|
| 465 |
connect(emb, SIGNAL(embeddedWindowDestroyed()), SLOT(updateTrayWindows())); |
connect(emb, SIGNAL(embeddedWindowDestroyed()), SLOT(updateTrayWindows())); |
| 466 |
emb->setMinimumSize(m_iconSize, m_iconSize); |
emb->getIconSize(m_iconSize); |
| 467 |
|
|
| 468 |
if (shouldHide(w)) |
if (shouldHide(w)) |
| 469 |
{ |
{ |
| 473 |
} |
} |
| 474 |
else |
else |
| 475 |
{ |
{ |
| 476 |
emb->hide(); |
//emb->hide(); |
| 477 |
emb->setBackground(); |
emb->setBackground(); |
| 478 |
emb->show(); |
emb->show(); |
| 479 |
m_shownWins.append(emb); |
m_shownWins.append(emb); |
| 517 |
{ |
{ |
| 518 |
for (; emb != lastEmb; ++emb) |
for (; emb != lastEmb; ++emb) |
| 519 |
{ |
{ |
| 520 |
(*emb)->hide(); |
//(*emb)->hide(); |
| 521 |
(*emb)->setBackground(); |
(*emb)->setBackground(); |
| 522 |
(*emb)->show(); |
(*emb)->show(); |
| 523 |
} |
} |
| 746 |
} |
} |
| 747 |
|
|
| 748 |
int currentHeight = height(); |
int currentHeight = height(); |
| 749 |
int minHeight = m_iconSize + 4; |
if (currentHeight != h) |
|
if (currentHeight != h && currentHeight != minHeight) |
|
| 750 |
{ |
{ |
| 751 |
SystemTrayApplet* me = const_cast<SystemTrayApplet*>(this); |
SystemTrayApplet* me = const_cast<SystemTrayApplet*>(this); |
| 752 |
me->setMinimumSize(0, 0); |
me->setMinimumSize(0, 0); |
| 765 |
} |
} |
| 766 |
|
|
| 767 |
int currentWidth = width(); |
int currentWidth = width(); |
| 768 |
int minSize = m_iconSize + 4; |
if (currentWidth != w) |
|
if (currentWidth != w && currentWidth != minSize) |
|
| 769 |
{ |
{ |
| 770 |
SystemTrayApplet* me = const_cast<SystemTrayApplet*>(this); |
SystemTrayApplet* me = const_cast<SystemTrayApplet*>(this); |
| 771 |
me->setMinimumSize(0, 0); |
me->setMinimumSize(0, 0); |
| 782 |
} |
} |
| 783 |
|
|
| 784 |
|
|
| 785 |
void SystemTrayApplet::resizeEvent( QResizeEvent* e ) |
void SystemTrayApplet::resizeEvent( QResizeEvent* ) |
| 786 |
{ |
{ |
|
KPanelApplet::resizeEvent(e); |
|
|
|
|
| 787 |
layoutTray(); |
layoutTray(); |
| 788 |
// we need to give ourselves a chance to adjust our size before calling this |
// we need to give ourselves a chance to adjust our size before calling this |
| 789 |
QTimer::singleShot(0, this, SIGNAL(updateLayout())); |
QTimer::singleShot(0, this, SIGNAL(updateLayout())); |
| 806 |
int i = 0, line, nbrOfLines, heightWidth; |
int i = 0, line, nbrOfLines, heightWidth; |
| 807 |
bool showExpandButton = m_expandButton && m_expandButton->isVisibleTo(this); |
bool showExpandButton = m_expandButton && m_expandButton->isVisibleTo(this); |
| 808 |
delete m_layout; |
delete m_layout; |
| 809 |
m_layout = new QGridLayout(this, 1, 1, 2, 2); |
m_layout = new QGridLayout(this, 1, 1, ICON_MARGIN, ICON_MARGIN); |
| 810 |
|
|
| 811 |
if (m_expandButton) |
if (m_expandButton) |
| 812 |
{ |
{ |
| 826 |
|
|
| 827 |
// |
// |
| 828 |
// The margin and spacing specified in the layout implies that: |
// The margin and spacing specified in the layout implies that: |
| 829 |
// [-- 2 pixels --] [-- first icon --] [-- 2 pixels --] ... [-- 2 pixels --] [-- last icon --] [-- 2 pixels --] |
// [-- ICON_MARGIN pixels --] [-- first icon --] [-- ICON_MARGIN pixels --] ... [-- ICON_MARGIN pixels --] [-- last icon --] [-- ICON_MARGIN pixels --] |
| 830 |
// |
// |
| 831 |
// So, if we say that iconWidth is the icon width plus the 2 pixels spacing, then the available width for the icons |
// So, if we say that iconWidth is the icon width plus the ICON_MARGIN pixels spacing, then the available width for the icons |
| 832 |
// is the widget width minus 2 pixels margin. Forgetting these 2 pixels broke the layout algorithm in KDE <= 3.5.9. |
// is the widget width minus ICON_MARGIN pixels margin. Forgetting these ICON_MARGIN pixels broke the layout algorithm in KDE <= 3.5.9. |
| 833 |
// |
// |
| 834 |
// This fix makes the workaround in the heightForWidth() and widthForHeight() methods unneeded. |
// This fix makes the workarounds in the heightForWidth() and widthForHeight() methods unneeded. |
| 835 |
// |
// |
| 836 |
|
|
| 837 |
if (orientation() == Vertical) |
if (orientation() == Vertical) |
| 838 |
{ |
{ |
| 839 |
int iconWidth = maxIconWidth() + 2; // +2 for the margins that implied by the layout |
int iconWidth = maxIconWidth() + ICON_MARGIN; // +2 for the margins that implied by the layout |
| 840 |
heightWidth = width() - 2; |
heightWidth = width() - ICON_MARGIN; |
| 841 |
// to avoid nbrOfLines=0 we ensure heightWidth >= iconWidth! |
// to avoid nbrOfLines=0 we ensure heightWidth >= iconWidth! |
| 842 |
heightWidth = heightWidth < iconWidth ? iconWidth : heightWidth; |
heightWidth = heightWidth < iconWidth ? iconWidth : heightWidth; |
| 843 |
nbrOfLines = heightWidth / iconWidth; |
nbrOfLines = heightWidth / iconWidth; |
| 858 |
emb != lastEmb; ++emb) |
emb != lastEmb; ++emb) |
| 859 |
{ |
{ |
| 860 |
line = i % nbrOfLines; |
line = i % nbrOfLines; |
| 861 |
(*emb)->hide(); |
//(*emb)->hide(); |
| 862 |
(*emb)->show(); |
(*emb)->show(); |
| 863 |
m_layout->addWidget(*emb, col, line, |
m_layout->addWidget(*emb, col, line, |
| 864 |
Qt::AlignHCenter | Qt::AlignVCenter); |
Qt::AlignHCenter | Qt::AlignVCenter); |
| 865 |
|
|
| 866 |
if (line + 1 == nbrOfLines) |
if ((line + 1) == nbrOfLines) |
| 867 |
{ |
{ |
| 868 |
++col; |
++col; |
| 869 |
} |
} |
| 877 |
emb != lastEmb; ++emb) |
emb != lastEmb; ++emb) |
| 878 |
{ |
{ |
| 879 |
line = i % nbrOfLines; |
line = i % nbrOfLines; |
| 880 |
(*emb)->hide(); |
//(*emb)->hide(); |
| 881 |
(*emb)->show(); |
(*emb)->show(); |
| 882 |
m_layout->addWidget(*emb, col, line, |
m_layout->addWidget(*emb, col, line, |
| 883 |
Qt::AlignHCenter | Qt::AlignVCenter); |
Qt::AlignHCenter | Qt::AlignVCenter); |
| 884 |
|
|
| 885 |
if (line + 1 == nbrOfLines) |
if ((line + 1) == nbrOfLines) |
| 886 |
{ |
{ |
| 887 |
++col; |
++col; |
| 888 |
} |
} |
| 892 |
} |
} |
| 893 |
else // horizontal |
else // horizontal |
| 894 |
{ |
{ |
| 895 |
int iconHeight = maxIconHeight() + 2; // +2 for the margins that implied by the layout |
int iconHeight = maxIconHeight() + ICON_MARGIN; // +2 for the margins that implied by the layout |
| 896 |
heightWidth = height() - 2; |
heightWidth = height() - ICON_MARGIN; |
| 897 |
heightWidth = heightWidth < iconHeight ? iconHeight : heightWidth; // to avoid nbrOfLines=0 |
heightWidth = heightWidth < iconHeight ? iconHeight : heightWidth; // to avoid nbrOfLines=0 |
| 898 |
nbrOfLines = heightWidth / iconHeight; |
nbrOfLines = heightWidth / iconHeight; |
| 899 |
|
|
| 912 |
for (TrayEmbedList::const_iterator emb = m_hiddenWins.begin(); emb != lastEmb; ++emb) |
for (TrayEmbedList::const_iterator emb = m_hiddenWins.begin(); emb != lastEmb; ++emb) |
| 913 |
{ |
{ |
| 914 |
line = i % nbrOfLines; |
line = i % nbrOfLines; |
| 915 |
(*emb)->hide(); |
//(*emb)->hide(); |
| 916 |
(*emb)->show(); |
(*emb)->show(); |
| 917 |
m_layout->addWidget(*emb, line, col, |
m_layout->addWidget(*emb, line, col, |
| 918 |
Qt::AlignHCenter | Qt::AlignVCenter); |
Qt::AlignHCenter | Qt::AlignVCenter); |
| 919 |
|
|
| 920 |
if (line + 1 == nbrOfLines) |
if ((line + 1) == nbrOfLines) |
| 921 |
{ |
{ |
| 922 |
++col; |
++col; |
| 923 |
} |
} |
| 931 |
emb != lastEmb; ++emb) |
emb != lastEmb; ++emb) |
| 932 |
{ |
{ |
| 933 |
line = i % nbrOfLines; |
line = i % nbrOfLines; |
| 934 |
(*emb)->hide(); |
//(*emb)->hide(); |
| 935 |
(*emb)->show(); |
(*emb)->show(); |
| 936 |
m_layout->addWidget(*emb, line, col, |
m_layout->addWidget(*emb, line, col, |
| 937 |
Qt::AlignHCenter | Qt::AlignVCenter); |
Qt::AlignHCenter | Qt::AlignVCenter); |
| 938 |
|
|
| 939 |
if (line + 1 == nbrOfLines) |
if ((line + 1) == nbrOfLines) |
| 940 |
{ |
{ |
| 941 |
++col; |
++col; |
| 942 |
} |
} |
| 973 |
: QXEmbed( parent ), kde_tray( kdeTray ) |
: QXEmbed( parent ), kde_tray( kdeTray ) |
| 974 |
{ |
{ |
| 975 |
hide(); |
hide(); |
| 976 |
|
} |
| 977 |
|
|
| 978 |
|
void TrayEmbed::getIconSize(int defaultIconSize) |
| 979 |
|
{ |
| 980 |
|
QSize minSize = minimumSizeHint(); |
| 981 |
|
|
| 982 |
|
int width = minSize.width(); |
| 983 |
|
int height = minSize.height(); |
| 984 |
|
|
| 985 |
|
if (width < 1 || width > defaultIconSize) |
| 986 |
|
width = defaultIconSize; |
| 987 |
|
if (height < 1 || height > defaultIconSize) |
| 988 |
|
height = defaultIconSize; |
| 989 |
|
|
| 990 |
|
setFixedSize(width, height); |
| 991 |
setBackground(); |
setBackground(); |
| 992 |
} |
} |
| 993 |
|
|
| 1007 |
|
|
| 1008 |
if (!isHidden()) |
if (!isHidden()) |
| 1009 |
{ |
{ |
| 1010 |
hide(); |
XClearArea(x11Display(), embeddedWinId(), 0, 0, 0, 0, True); |
|
show(); |
|
| 1011 |
} |
} |
|
//XClearArea(x11Display(), embeddedWinId(), 0, 0, 0, 0, True); |
|
| 1012 |
} |
} |
| 1013 |
|
|