4040// enable to set font size for style name separately from other texts
4141TEnv::IntVar EnvSoftwareCurrentFontSize_StyleName (
4242 " SoftwareCurrentFontSize_StyleName" , 11 );
43+ extern TEnv::IntVar ShowNewStyleButton;
4344
4445using namespace PaletteViewerGUI ;
4546using namespace DVGui ;
@@ -230,6 +231,7 @@ int PageViewer::getCurrentStyleIndex() const {
230231/* ! Set current page to \b page and update view.
231232 */
232233void PageViewer::setPage (TPalette::Page *page) {
234+ if (m_page == page) return ;
233235 m_page = page;
234236 computeSize ();
235237 update ();
@@ -556,20 +558,19 @@ void PageViewer::drawToggleLink(QPainter &p, QRect &chipRect,
556558
557559// -----------------------------------------------------------------------------
558560/* ! Draw the chip name \b name inside rectangle \b chipRect using painter \b p.
559- * If the name is too wide to fit on the chip, use left align - to show the
560- * start of the name. Otherwise, use center align.
561- */
561+ * If the name is too wide to fit on the chip, use left align - to show the
562+ * start of the name. Otherwise, use center align.
563+ */
562564static void drawChipName (QPainter &p, const QRect &chipRect,
563- const std::wstring &name) {
565+ const std::wstring &name) {
564566 const QString nameQString = QString::fromStdWString (name);
565567 QRect textRect = p.boundingRect (chipRect, Qt::AlignCenter, nameQString);
566568
567569 if (chipRect.width () < textRect.width ()) {
568570 // align left if the name is too wide to fit on the chip
569- p.drawText (chipRect.adjusted (4 , 0 , -4 , 0 ),
570- Qt::AlignLeft | Qt::AlignVCenter, nameQString);
571- }
572- else {
571+ p.drawText (chipRect.adjusted (4 , 0 , -4 , 0 ), Qt::AlignLeft | Qt::AlignVCenter,
572+ nameQString);
573+ } else {
573574 // otherwise align by center
574575 p.drawText (chipRect, Qt::AlignCenter, nameQString);
575576 }
@@ -580,6 +581,7 @@ static void drawChipName(QPainter &p, const QRect &chipRect,
580581 */
581582void PageViewer::paintEvent (QPaintEvent *e) {
582583 QPainter p (this );
584+ QColor textColor = p.pen ().color ();
583585 if (m_chipPerRow == 0 ) {
584586 p.drawText (QPoint (5 , 25 ), tr (" - No Styles -" ));
585587 return ;
@@ -656,10 +658,11 @@ void PageViewer::paintEvent(QPaintEvent *e) {
656658 // toggle link
657659 drawToggleLink (p, chipRect, m_page->getStyle (i));
658660 }
659- if (!m_page->getPalette ()->isLocked ()) {
661+ if (ShowNewStyleButton && !m_page->getPalette ()->isLocked ()) {
660662 int j = getChipCount ();
661663 QRect rect = getItemRect (j);
662- p.setPen (QColor (200 , 200 , 200 ));
664+ p.setPen (
665+ QColor (textColor.red (), textColor.green (), textColor.blue (), 128 ));
663666 // p.fillRect(rect, QBrush(QColor(0, 0, 0, 64)));
664667 // p.drawRect(rect);
665668 tmpFont.setPointSize (16 );
@@ -671,7 +674,7 @@ void PageViewer::paintEvent(QPaintEvent *e) {
671674 // revert font set
672675 p.setFont (preFont);
673676 p.setPen (Qt::black);
674- }
677+ }
675678
676679 } else {
677680 int currentStyleIndex = getCurrentStyleIndex ();
@@ -805,8 +808,7 @@ void PageViewer::paintEvent(QPaintEvent *e) {
805808 // display mode
806809 if (m_nameDisplayMode == Style) {
807810 drawChipName (p, chipRect, name);
808- }
809- else if (m_nameDisplayMode == Original) {
811+ } else if (m_nameDisplayMode == Original) {
810812 if (origName != L" " ) {
811813 tmpFont.setItalic (true );
812814 p.setFont (tmpFont);
@@ -900,11 +902,12 @@ void PageViewer::paintEvent(QPaintEvent *e) {
900902 // draw link indicator
901903 drawToggleLink (p, chipRect, style);
902904 }
903- // draw new style chip
904- if (!m_page->getPalette ()->isLocked ()) {
905+ // draw new style chip
906+ if (ShowNewStyleButton && !m_page->getPalette ()->isLocked ()) {
905907 i = getChipCount ();
906- QRect chipRect = getItemRect (i).adjusted (0 , -1 , 0 , -1 );
907- p.setPen (QColor (200 , 200 , 200 ));
908+ QRect chipRect = getItemRect (i).adjusted (4 , 4 , -5 , -5 );
909+ p.setPen (
910+ QColor (textColor.red (), textColor.green (), textColor.blue (), 128 ));
908911 p.fillRect (chipRect, QBrush (QColor (0 , 0 , 0 , 64 )));
909912 p.drawRect (chipRect);
910913 tmpFont.setPointSize (16 );
@@ -993,13 +996,14 @@ void PageViewer::mousePressEvent(QMouseEvent *event) {
993996 }
994997 m_dragStartPosition = pos;
995998 if (indexInPage < 0 || indexInPage >= getChipCount ()) {
996- if (indexInPage == getChipCount () && !m_page->getPalette ()->isLocked ()) {
999+ if (ShowNewStyleButton && indexInPage == getChipCount () &&
1000+ !m_page->getPalette ()->isLocked ()) {
9971001 PaletteCmd::createStyle (getPaletteHandle (), getPage ());
9981002 } else {
9991003 // the user clicked out of the color chips.wants to deselect everything
10001004 // (leaving the selection active, for a possible paste)
1001- m_styleSelection->select (pageIndex);
1002- m_styleSelection->makeCurrent ();
1005+ m_styleSelection->select (pageIndex);
1006+ m_styleSelection->makeCurrent ();
10031007 }
10041008
10051009 update ();
@@ -1366,8 +1370,8 @@ bool PageViewer::event(QEvent *e) {
13661370 if (0 <= indexInPage && indexInPage < m_page->getStyleCount ()) {
13671371 TColorStyle *style = m_page->getStyle (indexInPage);
13681372 if (style) {
1369- int styleIndex = m_page->getStyleId (indexInPage);
1370- toolTip = " #" + QString::number (styleIndex) + " " +
1373+ int styleIndex = m_page->getStyleId (indexInPage);
1374+ toolTip = " #" + QString::number (styleIndex) + " " +
13711375 QString::fromStdWString (style->getName ());
13721376
13731377 int shortcutKey = m_page->getPalette ()->getStyleShortcut (styleIndex);
@@ -1376,8 +1380,8 @@ bool PageViewer::event(QEvent *e) {
13761380 (wchar_t )shortcutKey + L" )" );
13771381 }
13781382 }
1379- if (indexInPage == m_page->getStyleCount ()) {
1380- toolTip = tr (" New Style" );
1383+ if (ShowNewStyleButton && indexInPage == m_page->getStyleCount ()) {
1384+ toolTip = tr (" New Style" );
13811385 }
13821386 if (toolTip != " " )
13831387 QToolTip::showText (helpEvent->globalPos (), toolTip);
@@ -1471,7 +1475,8 @@ void PageViewer::computeSize() {
14711475 QSize chipSize = getChipSize ();
14721476 m_chipPerRow = m_viewMode == List ? 1 : (w - 8 ) / chipSize.width ();
14731477 if (m_chipPerRow == 0 ) m_chipPerRow = 1 ;
1474- int rowCount = (chipCount + m_chipPerRow) / m_chipPerRow;
1478+ if (ShowNewStyleButton) chipCount++;
1479+ int rowCount = (chipCount + m_chipPerRow - 1 ) / m_chipPerRow;
14751480 setMinimumSize (w, rowCount * chipSize.height () + 10 );
14761481}
14771482
0 commit comments