]> git.sesse.net Git - kdenlive/commitdiff
Update DVD wizard: use underline to show selected text, add shadows to text
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Wed, 24 Oct 2012 22:18:10 +0000 (00:18 +0200)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Wed, 24 Oct 2012 22:18:10 +0000 (00:18 +0200)
src/customtrackview.cpp
src/dvdwizard.cpp
src/dvdwizardmenu.cpp
src/dvdwizardmenu.h
src/widgets/dvdwizardmenu_ui.ui

index cba00f154de403d2bf8057de40d9248050613618..f4aa85ff4ca61a02c7ec70ed17ead5807e5afe4d 100644 (file)
@@ -2684,8 +2684,7 @@ void CustomTrackView::dropEvent(QDropEvent * event)
             groupSelectedItems(true);
         } else if (items.count() == 1) {
             m_dragItem = static_cast <AbstractClipItem *>(items.at(0));
-           ClipItem *selected = static_cast <ClipItem*>(m_dragItem);
-            emit clipItemSelected(selected, false);
+            emit clipItemSelected((ClipItem*) m_dragItem, false);
         }
         event->setDropAction(Qt::MoveAction);
         event->accept();
index 4cc09174e7cc097ec768f60d217513b5585f5460..aa36f6048a497c4a84a3cf767f3e8ea4d59928e3 100644 (file)
@@ -294,7 +294,7 @@ void DvdWizard::generateDvd()
         stream.appendChild(spu);
         spu.setAttribute("force", "yes");
         spu.setAttribute("start", "00:00:00.00");
-        spu.setAttribute("image", temp1.fileName());
+        //spu.setAttribute("image", temp1.fileName());
        spu.setAttribute("select", temp2.fileName());
         spu.setAttribute("highlight", temp3.fileName());
         /*spu.setAttribute("autoorder", "rows");*/
index cc285bda01a54cc925a4164dbe28aed6abc7cc50..38ac05a719ee74df68a56523817680411d6a3736 100644 (file)
 
 #include <KDebug>
 #include <KColorScheme>
+
+#if KDE_IS_VERSION(4,6,0)
+#include <QGraphicsDropShadowEffect>
+#endif
+
+
 #include "kthumb.h"
 
 DvdWizardMenu::DvdWizardMenu(const QString &profile, QWidget *parent) :
         QWizardPage(parent),
         m_color(NULL),
-        m_safeRect(NULL)
+        m_safeRect(NULL),
+        m_finalSize(720, 576)
 {
     m_view.setupUi(this);
     m_view.play_text->setText(i18n("Play"));
@@ -80,15 +87,24 @@ DvdWizardMenu::DvdWizardMenu(const QString &profile, QWidget *parent) :
     m_safeRect->setPen(pen);
     m_safeRect->setZValue(5);
     m_scene->addItem(m_safeRect);
-
     checkBackgroundType(0);
 
-
     // create menu button
     DvdButton *button = new DvdButton(m_view.play_text->text());
     QFont font = m_view.font_family->currentFont();
     font.setPixelSize(m_view.font_size->value());
-    font.setStyleStrategy(QFont::NoAntialias);
+    //font.setStyleStrategy(QFont::NoAntialias);
+#if KDE_IS_VERSION(4,6,0)
+    if (m_view.use_shadow->isChecked()) {
+       QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect(this);
+       shadow->setBlurRadius(7);
+       shadow->setOffset(4, 4);
+       button->setGraphicsEffect(shadow);
+    }
+    connect(m_view.use_shadow, SIGNAL(stateChanged(int)), this, SLOT(slotEnableShadows(int)));
+#elif KDE_IS_VERSION(4,6,0)
+    m_view.use_shadow->setHidden(true);
+#endif
     button->setFont(font);
     button->setDefaultTextColor(m_view.text_color->color());
     button->setZValue(4);
@@ -138,8 +154,25 @@ DvdWizardMenu::~DvdWizardMenu()
     delete m_scene;
 }
 
-// virtual
+void DvdWizardMenu::slotEnableShadows(int enable)
+{
+#if KDE_IS_VERSION(4,6,0)
+    QList<QGraphicsItem *> list = m_scene->items();
+    for (int i = 0; i < list.count(); i++) {
+        if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
+            if (enable) {
+               QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect(this);
+               shadow->setBlurRadius(7);
+               shadow->setOffset(4, 4);
+               list.at(i)->setGraphicsEffect(shadow);
+           }
+            else list.at(i)->setGraphicsEffect(NULL);
+        }
+    }
+#endif
+}
 
+// virtual
 bool DvdWizardMenu::isComplete() const
 {
     m_view.error_message->setHidden(true);
@@ -286,12 +319,20 @@ void DvdWizardMenu::addButton()
     DvdButton *button = new DvdButton(m_view.play_text->text());
     QFont font = m_view.font_family->currentFont();
     font.setPixelSize(m_view.font_size->value());
-    font.setStyleStrategy(QFont::NoAntialias);
+#if KDE_IS_VERSION(4,6,0)
+    if (m_view.use_shadow->isChecked()) {
+       QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect(this);
+       shadow->setBlurRadius(7);
+       shadow->setOffset(4, 4);
+       button->setGraphicsEffect(shadow);
+    }
+#endif
+    //font.setStyleStrategy(QFont::NoAntialias);
     button->setFont(font);
-    button->setDefaultTextColor(m_view.text_color->color());
     button->setZValue(4);
     QRectF r = button->sceneBoundingRect();
     m_scene->addItem(button);
+    updateColor(m_view.text_color->color());
     button->setPos((m_width - r.width()) / 2, (m_height - r.height()) / 2);
     button->setSelected(true);
 }
@@ -311,10 +352,12 @@ void DvdWizardMenu::changeProfile(bool isPal)
 {
     m_isPal = isPal;
     if (isPal == false) {
-        m_width = 720;
+       m_finalSize = QSize(720, 480);
+        m_width = 640;
         m_height = 480;
     } else {
-        m_width = 720;
+       m_finalSize = QSize(720, 576);
+        m_width = 768;
         m_height = 576;
     }
     updatePreview();
@@ -431,7 +474,7 @@ void DvdWizardMenu::buildButton()
     button->setPlainText(m_view.play_text->text());
     QFont font = m_view.font_family->currentFont();
     font.setPixelSize(m_view.font_size->value());
-    font.setStyleStrategy(QFont::NoAntialias);
+    //font.setStyleStrategy(QFont::NoAntialias);
     button->setFont(font);
     button->setDefaultTextColor(m_view.text_color->color());
 }
@@ -442,6 +485,60 @@ void DvdWizardMenu::updateColor()
     m_view.menu_preview->viewport()->update();
 }
 
+void DvdWizardMenu::prepareUnderLines()
+{
+    QList<QGraphicsItem *> list = m_scene->items();
+    for (int i = 0; i < list.count(); i++) {
+        if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
+           QRectF r = list.at(i)->sceneBoundingRect();
+           int bottom = r.bottom() - 1;
+           if (bottom % 2 == 1) bottom = bottom - 1;
+           int underlineHeight = r.height() / 10;
+           if (underlineHeight % 2 == 1) underlineHeight = underlineHeight - 1;
+           underlineHeight = qMin(underlineHeight, 10);
+           underlineHeight = qMax(underlineHeight, 2);
+           r.setTop(bottom - underlineHeight);
+           r.adjust(2, 0, -2, 0);
+           QGraphicsRectItem *underline = new QGraphicsRectItem(r);
+           underline->setData(Qt::UserRole, QString("underline"));
+           m_scene->addItem(underline);
+           list.at(i)->setVisible(false);
+       }
+    }
+}
+
+void DvdWizardMenu::resetUnderLines()
+{
+    QList<QGraphicsItem *> list = m_scene->items();
+    QList<QGraphicsItem *> toDelete;
+    for (int i = 0; i < list.count(); i++) {
+       if (list.at(i)->data(Qt::UserRole).toString() == "underline") {
+           toDelete.append(list.at(i));
+       }
+        if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
+           list.at(i)->setVisible(true);
+       }
+    }
+    while (!toDelete.isEmpty()) {
+       QGraphicsItem *item = toDelete.takeFirst();
+       delete item;
+    }
+}
+
+void DvdWizardMenu::updateUnderlineColor(QColor c)
+{
+    QList<QGraphicsItem *> list = m_scene->items();
+    for (int i = 0; i < list.count(); i++) {
+        if (list.at(i)->data(Qt::UserRole).toString() == "underline") {
+            QGraphicsRectItem *underline = static_cast < QGraphicsRectItem* >(list.at(i));
+           underline->setPen(Qt::NoPen);
+           c.setAlpha(150);
+           underline->setBrush(c);
+        }
+    }
+}
+
+
 void DvdWizardMenu::updateColor(QColor c)
 {
     DvdButton *button = NULL;
@@ -462,19 +559,20 @@ void DvdWizardMenu::createButtonImages(const QString &img1, const QString &img2,
         if (m_safeRect->scene() != 0) m_scene->removeItem(m_safeRect);
         if (m_color->scene() != 0) m_scene->removeItem(m_color);
         if (m_background->scene() != 0) m_scene->removeItem(m_background);
+       prepareUnderLines();
 #if QT_VERSION >= 0x040800
-        QImage img(m_width, m_height, QImage::Format_ARGB32);
+        QImage img(m_finalSize.width(), m_finalSize.height(), QImage::Format_ARGB32);
         img.fill(Qt::transparent);
-        updateColor(m_view.text_color->color());
+       updateUnderlineColor(m_view.text_color->color());
 #else
-       QImage img(m_width, m_height, QImage::Format_Mono);
+       QImage img(m_finalSize.width(), m_finalSize.height(), QImage::Format_Mono);
         img.fill(Qt::white);
-        updateColor(Qt::black);
+       updateUnderlineColor(Qt::black);
 #endif
         QPainter p(&img);
-        p.setRenderHints(QPainter::Antialiasing, false);
-        p.setRenderHints(QPainter::TextAntialiasing, false);
-        m_scene->render(&p, QRectF(0, 0, m_width, m_height));
+        //p.setRenderHints(QPainter::Antialiasing, false);
+        //p.setRenderHints(QPainter::TextAntialiasing, false);
+        m_scene->render(&p, QRectF(0, 0, m_finalSize.width(), m_finalSize.height()), QRectF(0, 0, m_width, m_height), Qt::IgnoreAspectRatio);
         p.end();
 #if QT_VERSION >= 0x040800
 #elif QT_VERSION >= 0x040600 
@@ -487,14 +585,14 @@ void DvdWizardMenu::createButtonImages(const QString &img1, const QString &img2,
 
 #if QT_VERSION >= 0x040800
         img.fill(Qt::transparent);
-       updateColor(m_view.highlighted_color->color());
+       updateUnderlineColor(m_view.highlighted_color->color());
 #else
         img.fill(Qt::white);
 #endif
         p.begin(&img);
-        p.setRenderHints(QPainter::Antialiasing, false);
-        p.setRenderHints(QPainter::TextAntialiasing, false);
-        m_scene->render(&p, QRectF(0, 0, m_width, m_height));
+        //p.setRenderHints(QPainter::Antialiasing, false);
+        //p.setRenderHints(QPainter::TextAntialiasing, false);
+       m_scene->render(&p, QRectF(0, 0, m_finalSize.width(), m_finalSize.height()), QRectF(0, 0, m_width, m_height), Qt::IgnoreAspectRatio);
         p.end();
 #if QT_VERSION >= 0x040800
 #elif QT_VERSION >= 0x040600
@@ -507,14 +605,14 @@ void DvdWizardMenu::createButtonImages(const QString &img1, const QString &img2,
 
 #if QT_VERSION >= 0x040800
         img.fill(Qt::transparent);
-       updateColor(m_view.selected_color->color());
+       updateUnderlineColor(m_view.selected_color->color());
 #else
         img.fill(Qt::white);
 #endif
        p.begin(&img);
-        p.setRenderHints(QPainter::Antialiasing, false);
-        p.setRenderHints(QPainter::TextAntialiasing, false);
-        m_scene->render(&p, QRectF(0, 0, m_width, m_height));
+        //p.setRenderHints(QPainter::Antialiasing, false);
+        //p.setRenderHints(QPainter::TextAntialiasing, false);
+        m_scene->render(&p, QRectF(0, 0, m_finalSize.width(), m_finalSize.height()), QRectF(0, 0, m_width, m_height), Qt::IgnoreAspectRatio);
         p.end();
 #if QT_VERSION >= 0x040800
 #elif QT_VERSION >= 0x040600
@@ -524,8 +622,7 @@ void DvdWizardMenu::createButtonImages(const QString &img1, const QString &img2,
         img.setNumColors(4);
 #endif
         img.save(img2);
-        updateColor();
-
+        resetUnderLines();
         m_scene->addItem(m_safeRect);
         m_scene->addItem(m_color);
         if (m_view.background_list->currentIndex() > 0) m_scene->addItem(m_background);
@@ -535,7 +632,21 @@ void DvdWizardMenu::createButtonImages(const QString &img1, const QString &img2,
 
 void DvdWizardMenu::createBackgroundImage(const QString &overlayMenu, const QString &img1)
 {
-    QImage img;
+    m_scene->clearSelection();
+    if (m_safeRect->scene() != 0) m_scene->removeItem(m_safeRect);
+    QImage img(m_width, m_height, QImage::Format_ARGB32);
+    updateColor(m_view.text_color->color());
+    QPainter p(&img);
+    p.setRenderHints(QPainter::Antialiasing, true);
+    p.setRenderHints(QPainter::TextAntialiasing, true);
+    m_scene->render(&p, QRectF(0, 0, img.width(), img.height()));
+    p.end();
+    img.save(img1);
+    m_scene->addItem(m_safeRect);
+    return;
+       
+  
+    /*QImage img;
     if (m_view.background_list->currentIndex() == 0) {
         // color background
         if (m_isPal)
@@ -560,7 +671,7 @@ void DvdWizardMenu::createBackgroundImage(const QString &overlayMenu, const QStr
     QRectF src(0, 0, menu.width(), menu.height());
     p.drawImage(target, menu, src);
     p.end();
-    img.save(img1);
+    img.save(img1);*/
 }
 
 bool DvdWizardMenu::createMenu() const
@@ -588,16 +699,18 @@ QMap <QString, QRect> DvdWizardMenu::buttonsInfo()
 {
     QMap <QString, QRect> info;
     QList<QGraphicsItem *> list = m_scene->items();
+    double ratio = (double) m_finalSize.width() / m_width;
     for (int i = 0; i < list.count(); i++) {
         if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
             DvdButton *button = static_cast < DvdButton* >(list.at(i));
-            QRect r = list.at(i)->sceneBoundingRect().toRect();
-            // Make sure y1 is not odd (requested by spumux)
-            if (r.height() % 2 == 1) r.setHeight(r.height() + 1);
-            if (r.y() % 2 == 1) r.setY(r.y() - 1);
+           QRectF r = button->sceneBoundingRect();
+           QRect adjustedRect(r.x() * ratio, r.y(), r.width() * ratio, r.height());
+           // Make sure y1 is not odd (requested by spumux)
+            if (adjustedRect.height() % 2 == 1) adjustedRect.setHeight(adjustedRect.height() + 1);
+            if (adjustedRect.y() % 2 == 1) adjustedRect.setY(adjustedRect.y() - 1);
             QString command = button->command();
             if (button->backMenu()) command.prepend("g1 = 999;");
-            info.insertMulti(command, r);
+            info.insertMulti(command, adjustedRect);
         }
     }
     return info;
@@ -627,6 +740,7 @@ QDomElement DvdWizardMenu::toXml() const
     xml.setAttribute("text_color", m_view.text_color->color().name());
     xml.setAttribute("selected_color", m_view.selected_color->color().name());
     xml.setAttribute("highlighted_color", m_view.highlighted_color->color().name());
+    xml.setAttribute("text_shadow", (int) m_view.use_shadow->isChecked());
 
     QList<QGraphicsItem *> list = m_scene->items();
     int buttonCount = 0;
@@ -673,6 +787,8 @@ void DvdWizardMenu::loadXml(QDomElement xml)
     m_view.selected_color->setColor(xml.attribute("selected_color"));
     m_view.highlighted_color->setColor(xml.attribute("highlighted_color"));
 
+    m_view.use_shadow->setChecked(xml.attribute("text_shadow").toInt());
+
     QDomNodeList buttons = xml.elementsByTagName("button");
     kDebug() << "// LOADING MENU 2" << buttons.count();
 
@@ -694,7 +810,16 @@ void DvdWizardMenu::loadXml(QDomElement xml)
         DvdButton *button = new DvdButton(e.attribute("text"));
         QFont font(e.attribute("font_family"));
         font.setPixelSize(e.attribute("font_size").toInt());
-        font.setStyleStrategy(QFont::NoAntialias);
+#if KDE_IS_VERSION(4,6,0)
+       if (m_view.use_shadow->isChecked()) {
+           QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect(this);
+           shadow->setBlurRadius(7);
+           shadow->setOffset(4, 4);
+           button->setGraphicsEffect(shadow);
+       }
+#endif
+
+        //font.setStyleStrategy(QFont::NoAntialias);
         button->setFont(font);
         button->setTarget(e.attribute("target").toInt(), e.attribute("command"));
         button->setBackMenu(e.attribute("backtomenu").toInt());
index bde321103b3be2a35d0cfaddf18ec9afb56f33e9..e8d6f07de258cd063fa1f4c4f8332c7cc73d4382 100644 (file)
@@ -144,6 +144,8 @@ public:
     void changeProfile(bool isPal);
     QDomElement toXml() const;
     void loadXml(QDomElement xml);
+    void prepareUnderLines();
+    void resetUnderLines();
 
 private:
     Ui::DvdWizardMenu_UI m_view;
@@ -154,6 +156,7 @@ private:
     QGraphicsRectItem *m_safeRect;
     int m_width;
     int m_height;
+    QSize m_finalSize;
 #if KDE_IS_VERSION(4,7,0)
     KMessageWidget *m_menuMessage;
 #endif
@@ -171,9 +174,11 @@ private slots:
     void deleteButton();
     void updateColor();
     void updateColor(QColor c);
+    void updateUnderlineColor(QColor c);
     void setBackToMenu(bool backToMenu);
     void slotZoom();
     void slotUnZoom();
+    void slotEnableShadows(int enable);
 };
 
 #endif
index f7b3fe9b5101d57d5db93560626a3a13eeba57c5..ba524d852e00d26aa84707fc6f09781096298f2f 100644 (file)
@@ -6,8 +6,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>335</width>
-    <height>371</height>
+    <width>439</width>
+    <height>368</height>
    </rect>
   </property>
   <layout class="QGridLayout" name="gridLayout_5">
             </property>
            </widget>
           </item>
-          <item row="0" column="1" colspan="2">
+          <item row="0" column="1">
            <widget class="KLineEdit" name="play_text"/>
           </item>
-          <item row="0" column="3">
+          <item row="0" column="2">
            <widget class="QLabel" name="label_6">
             <property name="text">
              <string>Target</string>
             </property>
            </widget>
           </item>
-          <item row="0" column="4">
+          <item row="0" column="3">
            <widget class="KComboBox" name="target_list">
             <property name="sizePolicy">
              <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
             </property>
            </widget>
           </item>
+          <item row="0" column="4" colspan="3">
+           <widget class="QCheckBox" name="back_to_menu">
+            <property name="text">
+             <string>Back to menu</string>
+            </property>
+           </widget>
+          </item>
           <item row="1" column="0">
            <widget class="QLabel" name="label_4">
             <property name="text">
             </property>
            </widget>
           </item>
-          <item row="1" column="2" colspan="4">
+          <item row="1" column="2" colspan="3">
            <widget class="QFontComboBox" name="font_family"/>
           </item>
-          <item row="2" column="0" colspan="2">
-           <widget class="QLabel" name="label_5">
+          <item row="1" column="5">
+           <widget class="KColorButton" name="text_color">
+            <property name="text">
+             <string/>
+            </property>
+            <property name="color">
+             <color>
+              <red>255</red>
+              <green>255</green>
+              <blue>255</blue>
+             </color>
+            </property>
+           </widget>
+          </item>
+          <item row="1" column="6">
+           <widget class="QCheckBox" name="use_shadow">
             <property name="text">
-             <string>Button colors</string>
+             <string>Shadow</string>
+            </property>
+            <property name="checked">
+             <bool>true</bool>
             </property>
            </widget>
           </item>
-          <item row="2" column="2" colspan="4">
+          <item row="2" column="0" colspan="7">
            <layout class="QHBoxLayout" name="horizontalLayout">
             <item>
-             <widget class="KColorButton" name="text_color">
+             <widget class="QLabel" name="label_2">
               <property name="text">
-               <string/>
+               <string>Underline</string>
               </property>
+             </widget>
+            </item>
+            <item>
+             <widget class="KColorButton" name="highlighted_color">
               <property name="color">
                <color>
                 <red>255</red>
-                <green>255</green>
-                <blue>255</blue>
+                <green>85</green>
+                <blue>0</blue>
                </color>
               </property>
              </widget>
              </widget>
             </item>
             <item>
-             <widget class="KColorButton" name="highlighted_color">
-              <property name="color">
-               <color>
-                <red>255</red>
-                <green>85</green>
-                <blue>0</blue>
-               </color>
+             <spacer name="horizontalSpacer">
+              <property name="orientation">
+               <enum>Qt::Horizontal</enum>
               </property>
-             </widget>
+              <property name="sizeHint" stdset="0">
+               <size>
+                <width>40</width>
+                <height>20</height>
+               </size>
+              </property>
+             </spacer>
             </item>
            </layout>
           </item>
-          <item row="0" column="5">
-           <widget class="QCheckBox" name="back_to_menu">
-            <property name="text">
-             <string>Back to menu</string>
-            </property>
-           </widget>
-          </item>
          </layout>
         </widget>
         <widget class="QWidget" name="tab_2">
  </widget>
  <customwidgets>
   <customwidget>
-   <class>KIntSpinBox</class>
-   <extends>QSpinBox</extends>
-   <header>knuminput.h</header>
+   <class>KColorButton</class>
+   <extends>QPushButton</extends>
+   <header>kcolorbutton.h</header>
   </customwidget>
   <customwidget>
-   <class>KUrlRequester</class>
-   <extends>QFrame</extends>
-   <header>kurlrequester.h</header>
+   <class>KComboBox</class>
+   <extends>QComboBox</extends>
+   <header>kcombobox.h</header>
   </customwidget>
   <customwidget>
    <class>KLineEdit</class>
    <header>klineedit.h</header>
   </customwidget>
   <customwidget>
-   <class>KComboBox</class>
-   <extends>QComboBox</extends>
-   <header>kcombobox.h</header>
+   <class>KIntSpinBox</class>
+   <extends>QSpinBox</extends>
+   <header>knuminput.h</header>
   </customwidget>
   <customwidget>
-   <class>KColorButton</class>
-   <extends>QPushButton</extends>
-   <header>kcolorbutton.h</header>
+   <class>KUrlRequester</class>
+   <extends>QFrame</extends>
+   <header>kurlrequester.h</header>
   </customwidget>
  </customwidgets>
  <resources/>