Skip to content

Commit d838c36

Browse files
Save font desc through CEGUI.
Some drafts for Ctrl+Drag positioning.
1 parent fbfd08e commit d838c36

2 files changed

Lines changed: 10 additions & 28 deletions

File tree

src/cegui/CEGUIManager.cpp

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -653,35 +653,13 @@ QStringList CEGUIManager::getAvailableFonts() const
653653

654654
bool CEGUIManager::saveFont(CEGUI::Font& font, bool addToSchemes) const
655655
{
656-
const QString fontName = CEGUIUtils::stringToQString(font.getName());
657-
const QString fontDescFileName = fontName + ".font";
656+
const QString fontDescFileName = CEGUIUtils::stringToQString(font.getName()) + ".font";
658657

659658
// Save an XML font description to the project
660-
// TODO: rewrite with FontManager::writeFontToStream!
661-
662-
QDomDocument doc;
663-
auto xmlHeader = doc.createProcessingInstruction("xml", "version=\"1.0\" encoding=\"utf-8\"");
664-
doc.appendChild(xmlHeader);
665-
auto xmlRoot = doc.createElement("Font");
666-
xmlRoot.setAttribute("version", "3");
667-
xmlRoot.setAttribute("name", fontName);
668-
xmlRoot.setAttribute("filename", CEGUIUtils::stringToQString(font.getFileName()));
669-
xmlRoot.setAttribute("type", CEGUIUtils::stringToQString(font.getTypeName()));
670-
if (auto freeTypeFont = dynamic_cast<CEGUI::FreeTypeFont*>(&font))
671-
xmlRoot.setAttribute("size", QString::number(static_cast<int>(freeTypeFont->getSize())));
672-
xmlRoot.setAttribute("nativeHorzRes", QString::number(static_cast<int>(font.getNativeResolution().d_width)));
673-
xmlRoot.setAttribute("nativeVertRes", QString::number(static_cast<int>(font.getNativeResolution().d_height)));
674-
xmlRoot.setAttribute("autoScaled", CEGUIUtils::stringToQString(CEGUI::PropertyHelper<CEGUI::AutoScaledMode>::toString(font.getAutoScaled())));
675-
doc.appendChild(xmlRoot);
676-
677659
{
678660
const auto dstFontDescPath = currentProject->getResourceFilePath(fontDescFileName, "fonts");
679-
QFile file(dstFontDescPath);
680-
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) return false;
681-
682-
QTextStream stream(&file);
683-
doc.save(stream, 4);
684-
file.close();
661+
std::ofstream stream(dstFontDescPath.toStdString(), std::ios_base::out | std::ios_base::trunc);
662+
CEGUI::FontManager::getSingleton().writeFontToStream(font.getName(), stream);
685663
}
686664

687665
// Add a new font to all schemes
@@ -698,6 +676,8 @@ bool CEGUIManager::saveFont(CEGUI::Font& font, bool addToSchemes) const
698676
QFileInfo info = schemesIt.fileInfo();
699677
if (info.isDir() || info.suffix() != "scheme") continue;
700678

679+
QDomDocument doc;
680+
701681
// Open, read & close file. We will work with a DOM document.
702682
{
703683
QFile file(info.absoluteFilePath());

src/ui/layout/LayoutManipulator.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ void LayoutManipulator::dropEvent(QGraphicsSceneDragDropEvent* event)
354354
return;
355355
}
356356

357-
// Drop existing widgets into this widget as children with Ctrl+Drag
357+
// Drop existing widgets into this widget as children with Ctrl+Drag or from widget tree
358358
bytes = event->mimeData()->data("application/x-ceed-widget-paths");
359359
if (bytes.size() > 0)
360360
{
@@ -369,13 +369,15 @@ void LayoutManipulator::dropEvent(QGraphicsSceneDragDropEvent* event)
369369

370370
if (event->dropAction() == Qt::MoveAction)
371371
{
372+
_visualMode.moveWidgetsInHierarchy(std::move(widgetPaths), this, getWidget()->getChildCount());
373+
event->acceptProposedAction();
374+
372375
// calc offset
373376
// get pos of the widget in old parent (need widget that we started to drag, or always first? or drag start pos, if more than one widget?)
374377
// get pos of the drop inside this
375378
//event->scenePos() - scenePos();
379+
// Add move command
376380

377-
_visualMode.moveWidgetsInHierarchy(std::move(widgetPaths), this, getWidget()->getChildCount());
378-
event->acceptProposedAction();
379381
return;
380382
}
381383
}

0 commit comments

Comments
 (0)