Kaydet (Commit) 014b0674 authored tarafından Michael Meeks's avatar Michael Meeks

Encourage ValueSet to render a legend as well as an icon.

Change-Id: I83688a70b864bddb2af0a0a5b34968099c49d112
Reviewed-on: https://gerrit.libreoffice.org/19913Reviewed-by: 's avatarMichael Meeks <michael.meeks@collabora.com>
Tested-by: 's avatarMichael Meeks <michael.meeks@collabora.com>
üst f92c53f9
......@@ -307,12 +307,17 @@ public:
void DoubleClick();
virtual void UserDraw( const UserDrawEvent& rUDEvt );
/// Insert @rImage item.
void InsertItem(sal_uInt16 nItemId, const Image& rImage, size_t nPos = VALUESET_APPEND);
/// Insert @rImage item with @rStr as either a legend or tooltip depending on @bShowLegend.
void InsertItem(sal_uInt16 nItemId, const Image& rImage,
const OUString& rStr, size_t nPos = VALUESET_APPEND);
const OUString& rStr, size_t nPos = VALUESET_APPEND, bool bShowLegend = false);
/// Insert an @rColor item with @rStr tooltip.
void InsertItem(sal_uInt16 nItemId, const Color& rColor,
const OUString& rStr, size_t nPos = VALUESET_APPEND);
/// Insert an User Drawn item.
void InsertItem(sal_uInt16 nItemId, size_t nPos = VALUESET_APPEND);
/// Insert an User Drawn item with @rStr tooltip.
void InsertItem(sal_uInt16 nItemId, const OUString& rStr, size_t nPos = VALUESET_APPEND);
void RemoveItem(sal_uInt16 nItemId);
......@@ -336,8 +341,9 @@ public:
return mnUserVisLines;
}
void SetItemWidth( long nItemWidth = 0 );
void SetItemHeight( long nLineHeight = 0 );
Size GetLargestItemSize();
void RecalculateItemSizes();
void SelectItem( sal_uInt16 nItemId );
sal_uInt16 GetSelectItemId() const
......
......@@ -52,9 +52,6 @@
#include <algorithm>
#define TRANSITION_THUMB_WIDTH 64
#define TRANSITION_THUMB_HEIGHT 40
using namespace ::com::sun::star;
using ::com::sun::star::uno::Reference;
......@@ -389,8 +386,6 @@ public:
set_hexpand( true );
set_vexpand( true );
SetExtraSpacing( 2 );
SetItemWidth( TRANSITION_THUMB_WIDTH );
SetItemHeight( TRANSITION_THUMB_HEIGHT );
}
virtual ~TransitionPane() { disposeOnce(); }
......@@ -444,8 +439,11 @@ SlideTransitionPane::SlideTransitionPane(
mxView.set( mxModel->getCurrentController(), uno::UNO_QUERY );
// dummy list box of slide transitions for startup.
mpVS_TRANSITION_ICONS->InsertItem( 0, Image( BitmapEx( "sd/cmd/transition-none.png" ) ),
SD_RESSTR( STR_SLIDETRANSITION_NONE ) );
mpVS_TRANSITION_ICONS->InsertItem(
0, Image( BitmapEx( "sd/cmd/transition-none.png" ) ),
SD_RESSTR( STR_SLIDETRANSITION_NONE ),
VALUESET_APPEND, /* show legend */ true );
mpVS_TRANSITION_ICONS->RecalculateItemSizes();
// set defaults
mpCB_AUTO_PREVIEW->Check(); // automatic preview on
......@@ -1123,7 +1121,9 @@ IMPL_LINK_NOARG_TYPED(SlideTransitionPane, LateInitCallback, Timer *, void)
if ( aIcon.IsEmpty() ) // need a fallback
aIcon = BitmapEx( "sd/cmd/transition-none.png" );
mpVS_TRANSITION_ICONS->InsertItem( nPresetOffset + 1, Image( aIcon ), sLabel );
mpVS_TRANSITION_ICONS->InsertItem(
nPresetOffset + 1, Image( aIcon ), sLabel,
VALUESET_APPEND, /* show legend */ true );
m_aNumVariants[ pPreset->getSetId() ] = 1;
}
......@@ -1134,6 +1134,7 @@ IMPL_LINK_NOARG_TYPED(SlideTransitionPane, LateInitCallback, Timer *, void)
}
nPresetOffset++;
}
mpVS_TRANSITION_ICONS->RecalculateItemSizes();
SAL_INFO( "sd.transitions", "Item transition offsets in ValueSet:");
for( size_t i = 0; i < mpVS_TRANSITION_ICONS->GetItemCount(); ++i )
......
......@@ -42,6 +42,7 @@ enum ValueSetItemType
{
VALUESETITEM_NONE,
VALUESETITEM_IMAGE,
VALUESETITEM_IMAGE_AND_TEXT,
VALUESETITEM_COLOR,
VALUESETITEM_USERDRAW
};
......
......@@ -308,7 +308,9 @@ void ValueSet::ImplFormatItem(vcl::RenderContext& rRenderContext, ValueSetItem*
Size aRectSize = aRect.GetSize();
Point aPos(aRect.Left(), aRect.Top());
aPos.X() += (aRectSize.Width() - aImageSize.Width()) / 2;
aPos.Y() += (aRectSize.Height() - aImageSize.Height()) / 2;
if (pItem->meType != VALUESETITEM_IMAGE_AND_TEXT)
aPos.Y() += (aRectSize.Height() - aImageSize.Height()) / 2;
DrawImageFlags nImageStyle = DrawImageFlags::NONE;
if (!IsEnabled())
......@@ -323,6 +325,26 @@ void ValueSet::ImplFormatItem(vcl::RenderContext& rRenderContext, ValueSetItem*
}
else
maVirDev->DrawImage(aPos, pItem->maImage, nImageStyle);
if (pItem->meType == VALUESETITEM_IMAGE_AND_TEXT)
{
maVirDev->SetFont(rRenderContext.GetFont());
maVirDev->SetTextColor((nStyle & WB_MENUSTYLEVALUESET) ? rStyleSettings.GetMenuTextColor() : rStyleSettings.GetWindowTextColor());
maVirDev->SetTextFillColor();
long nTxtWidth = maVirDev->GetTextWidth(pItem->maText);
if (nTxtWidth > aRect.GetWidth())
maVirDev->SetClipRegion(vcl::Region(aRect));
maVirDev->DrawText(Point(aRect.Left() +
(aRect.GetWidth() - nTxtWidth) / 2,
aRect.Bottom() - maVirDev->GetTextHeight()),
pItem->maText);
if (nTxtWidth > aRect.GetWidth())
maVirDev->SetClipRegion();
}
}
}
......@@ -1584,11 +1606,12 @@ void ValueSet::InsertItem( sal_uInt16 nItemId, const Image& rImage, size_t nPos
}
void ValueSet::InsertItem( sal_uInt16 nItemId, const Image& rImage,
const OUString& rText, size_t nPos )
const OUString& rText, size_t nPos,
bool bShowLegend )
{
ValueSetItem* pItem = new ValueSetItem( *this );
pItem->mnId = nItemId;
pItem->meType = VALUESETITEM_IMAGE;
pItem->meType = bShowLegend ? VALUESETITEM_IMAGE_AND_TEXT : VALUESETITEM_IMAGE;
pItem->maImage = rImage;
pItem->maText = rText;
ImplInsertItem( pItem, nPos );
......@@ -1805,6 +1828,27 @@ void ValueSet::SetItemHeight( long nNewItemHeight )
}
}
/**
* An inelegant method; sets the item width & height such that
* all of the included items and their labels fit; if we can
* calculate that.
*/
void ValueSet::RecalculateItemSizes()
{
Size aLargestItem = GetLargestItemSize();
if ( mnUserItemWidth != aLargestItem.Width() ||
mnUserItemHeight != aLargestItem.Height() )
{
mnUserItemWidth = aLargestItem.Width();
mnUserItemHeight = aLargestItem.Height();
mbFormat = true;
queue_resize();
if ( IsReallyVisible() && IsUpdateMode() )
Invalidate();
}
}
void ValueSet::SelectItem( sal_uInt16 nItemId )
{
size_t nItemPos = 0;
......@@ -2286,9 +2330,9 @@ void ValueSet::SetHighlightHdl( const Link<ValueSet*,void>& rLink )
maHighlightHdl = rLink;
}
Size ValueSet::GetOptimalSize() const
Size ValueSet::GetLargestItemSize()
{
Size aLargestItemSize;
Size aLargestItem;
for (size_t i = 0, n = mItemList.size(); i < n; ++i)
{
......@@ -2296,18 +2340,33 @@ Size ValueSet::GetOptimalSize() const
if (!pItem->mbVisible)
continue;
if (pItem->meType != VALUESETITEM_IMAGE)
if (pItem->meType != VALUESETITEM_IMAGE &&
pItem->meType != VALUESETITEM_IMAGE_AND_TEXT)
{
//handle determining an optimal size for this case
// handle determining an optimal size for this case
continue;
}
Size aImageSize = pItem->maImage.GetSizePixel();
aLargestItemSize.Width() = std::max(aLargestItemSize.Width(), aImageSize.Width());
aLargestItemSize.Height() = std::max(aLargestItemSize.Height(), aImageSize.Height());
Size aSize = pItem->maImage.GetSizePixel();
if (pItem->meType == VALUESETITEM_IMAGE_AND_TEXT)
{
aSize.Height() += 3 * NAME_LINE_HEIGHT +
maVirDev->GetTextHeight();
aSize.Width() = std::max(aSize.Width(),
maVirDev->GetTextWidth(pItem->maText) + NAME_OFFSET);
}
aLargestItem.Width() = std::max(aLargestItem.Width(), aSize.Width());
aLargestItem.Height() = std::max(aLargestItem.Height(), aSize.Height());
}
return CalcWindowSizePixel(aLargestItemSize);
return aLargestItem;
}
Size ValueSet::GetOptimalSize() const
{
return CalcWindowSizePixel(
const_cast<ValueSet *>(this)->GetLargestItemSize());
}
void ValueSet::SetEdgeBlending(bool bNew)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment