Exemple #1
0
        private void customHoritonalAlignButton_Click(object sender, EventArgs e)
        {
            var listSelectedElements = ElementManager.Instance.SelectedElements;

            if (listSelectedElements == null || listSelectedElements.Count == 0)
            {
                return;
            }

            const string HORIZONTAL_SPACING   = "horizontal_spacing";
            const string APPLY_ELEMENT_WIDTHS = "apply_element_widths";
            const string ELEMENT_CENTERING    = "element_centering";

            var zQuery = new QueryPanelDialog("Custom Horizontal Align Elements", 450, 150, false);

            zQuery.SetIcon(CardMakerInstance.ApplicationIcon);

            zQuery.AddNumericBox("Horizontal Pixel Spacing", 0, int.MinValue, int.MaxValue, HORIZONTAL_SPACING);
            zQuery.AddCheckBox("Include Element Widths", false, APPLY_ELEMENT_WIDTHS);
            zQuery.AddPullDownBox("Vertical Centering", Enum.GetNames(typeof(ElementCenterAlign)), 0,
                                  ELEMENT_CENTERING);


            if (DialogResult.OK != zQuery.ShowDialog(CardMakerInstance.ApplicationForm))
            {
                return;
            }

            var nHorizontalSpace    = (int)zQuery.GetDecimal(HORIZONTAL_SPACING);
            var bApplyElementWidths = zQuery.GetBool(APPLY_ELEMENT_WIDTHS);
            var eCenterAlignment    = (ElementCenterAlign)zQuery.GetIndex(ELEMENT_CENTERING);

            // determine the centering
            var nCenterY = 0;

            switch (eCenterAlignment)
            {
            case ElementCenterAlign.FirstElement:
                nCenterY = listSelectedElements[0].y + (listSelectedElements[0].height / 2);
                break;

            case ElementCenterAlign.Layout:
                nCenterY = LayoutManager.Instance.ActiveLayout.height / 2;
                break;
            }

            var dictionaryOriginalPositions = ElementManager.Instance.GetUndoRedoPoints();

            // apply the translation
            var nX = listSelectedElements[0].x;

            for (var nIdx = 0; nIdx < listSelectedElements.Count; nIdx++)
            {
                var zElement = listSelectedElements[nIdx];
                zElement.x = nX;
                nX        += bApplyElementWidths ? zElement.width : 0;
                nX        += nHorizontalSpace;
                switch (eCenterAlignment)
                {
                case ElementCenterAlign.FirstElement:
                    if (0 < nIdx)
                    {
                        zElement.y = nCenterY - (zElement.width / 2);
                    }
                    break;

                case ElementCenterAlign.Layout:
                    zElement.y = nCenterY - (zElement.width / 2);
                    break;
                }
            }
            ElementManager.Instance.ConfigureUserAction(dictionaryOriginalPositions,
                                                        ElementManager.Instance.GetUndoRedoPoints());

            ElementManager.Instance.FireElementBoundsUpdateEvent();
        }
Exemple #2
0
        private void ExportViaPDFSharp(bool bExportAllLayouts)
        {
            var zQuery = new QueryPanelDialog("Export to PDF (via PDFSharp)", 750, false);

            zQuery.SetIcon(Icon);
            const string ORIENTATION    = "orientation";
            const string OUTPUT_FILE    = "output_file";
            const string OPEN_ON_EXPORT = "open_on_export";

            zQuery.AddPullDownBox("Page Orientation",
                                  new string[]
            {
                PageOrientation.Portrait.ToString(),
                PageOrientation.Landscape.ToString()
            },
                                  m_nPdfExportLastOrientationIndex,
                                  ORIENTATION);

            zQuery.AddFileBrowseBox("Output File", m_sPdfExportLastFile, "PDF files (*.pdf)|*.pdf|All files (*.*)|*.*", OUTPUT_FILE);
            zQuery.AddCheckBox("Open PDF on Export", m_bPdfExportLastOpen, OPEN_ON_EXPORT);

            if (DialogResult.OK != zQuery.ShowDialog(this))
            {
                return;
            }

            var nStartLayoutIdx = 0;
            var nEndLayoutIdx   = ProjectManager.Instance.LoadedProject.Layout.Length;

            if (!bExportAllLayouts)
            {
                int nIdx = ProjectManager.Instance.GetLayoutIndex(LayoutManager.Instance.ActiveLayout);
                if (-1 == nIdx)
                {
                    FormUtils.ShowErrorMessage("Unable to determine the current layout. Please select a layout in the tree view and try again.");
                    return;
                }
                nStartLayoutIdx = nIdx;
                nEndLayoutIdx   = nIdx + 1;
            }

            m_sPdfExportLastFile             = zQuery.GetString(OUTPUT_FILE);
            m_bPdfExportLastOpen             = zQuery.GetBool(OPEN_ON_EXPORT);
            m_nPdfExportLastOrientationIndex = zQuery.GetIndex(ORIENTATION);

            if (!m_sPdfExportLastFile.EndsWith(".pdf", StringComparison.CurrentCultureIgnoreCase))
            {
                m_sPdfExportLastFile += ".pdf";
            }

            var zFileCardExporter = new PdfSharpExporter(nStartLayoutIdx, nEndLayoutIdx, m_sPdfExportLastFile, zQuery.GetString(ORIENTATION));

            var zWait = new WaitDialog(
                2,
                zFileCardExporter.ExportThread,
                "Export",
                new string[] { "Layout", "Card" },
                450);

#if true
            zWait.ShowDialog(this);
#else
            zFileCardExporter.ExportThread();
#endif

            if (zWait.ThreadSuccess &&
                m_bPdfExportLastOpen &&
                File.Exists(m_sPdfExportLastFile))
            {
                Process.Start(m_sPdfExportLastFile);
            }
        }
Exemple #3
0
        private void setNameFormatToolStripMenuItem_Click(object sender, EventArgs e)
        {
            const string NAME                    = "NAME";
            const string ROTATION                = "ROTATION";
            const string EXPORT_WIDTH            = "EXPORT_WIDTH";
            const string EXPORT_HEIGHT           = "EXPORT_HEIGHT";
            const string EXPORT_TRANSPARENT      = "EXPORT_TRANSPARENT";
            const string EXPORT_PDF_AS_PAGE_BACK = "EXPORT_PDF_AS_PAGE_BACK";

            Type   typeObj         = treeView.SelectedNode.Tag.GetType();
            string sExistingFormat = string.Empty;
            var    zQuery          = new QueryPanelDialog("Configure Layout Export", 550, 300, false);

            zQuery.SetIcon(Resources.CardMakerIcon);

            if (typeof(Project) == typeObj)
            {
                sExistingFormat = ((Project)treeView.SelectedNode.Tag).exportNameFormat;
            }
            else if (typeof(ProjectLayout) == typeObj)
            {
                var zProjectLayout = ((ProjectLayout)treeView.SelectedNode.Tag);

                sExistingFormat = zProjectLayout.exportNameFormat;
                var nDefaultRotationIndex =
                    Math.Max(0, ProjectLayout.AllowedExportRotations.ToList()
                             .IndexOf(zProjectLayout.exportRotation.ToString()));
                zQuery.AddPullDownBox("Export Rotation (PDF/Export)", ProjectLayout.AllowedExportRotations,
                                      nDefaultRotationIndex, ROTATION);

                zQuery.AddCheckBox("Export PDF Layout Page as Back", zProjectLayout.exportPDFAsPageBack, EXPORT_PDF_AS_PAGE_BACK);

                var nColumns = 0;
                var nRows    = 0;

                if (zProjectLayout.exportWidth > 0)
                {
                    var nWidth = zProjectLayout.width + zProjectLayout.buffer;
                    nColumns = zProjectLayout.exportWidth / nWidth;
                }

                if (zProjectLayout.exportHeight > 0)
                {
                    var nHeight = zProjectLayout.width + zProjectLayout.buffer;
                    nRows = zProjectLayout.exportHeight / nHeight;
                }

                var numericColumns = zQuery.AddNumericBox("Stitched Columns (changes export width)", nColumns, 0, 100, "COLUMNS");

                var numericRows = zQuery.AddNumericBox("Stitched Rows (changes export height)", nRows, 0, 100, "ROWS");

                var numericExportWidth = zQuery.AddNumericBox("Export Width", zProjectLayout.exportWidth,
                                                              0, 65536, EXPORT_WIDTH);
                var numericExportHeight = zQuery.AddNumericBox("Export Height", zProjectLayout.exportHeight,
                                                               0, 65536, EXPORT_HEIGHT);
                zQuery.AddCheckBox("Export Transparent Background", zProjectLayout.exportTransparentBackground,
                                   EXPORT_TRANSPARENT);

                numericColumns.ValueChanged += (o, args) =>
                {
                    numericExportWidth.Value = (zProjectLayout.width * numericColumns.Value) +
                                               Math.Max(0, (numericColumns.Value - 1) * zProjectLayout.buffer);
                };

                numericRows.ValueChanged += (o, args) =>
                {
                    numericExportHeight.Value = (zProjectLayout.height * numericRows.Value) +
                                                Math.Max(0, (numericRows.Value - 1) * zProjectLayout.buffer);
                };
            }

            zQuery.AddTextBox("Name Format", sExistingFormat ?? string.Empty, false, NAME);

            if (DialogResult.OK == zQuery.ShowDialog(this))
            {
                if (typeof(Project) == typeObj)
                {
                    ((Project)treeView.SelectedNode.Tag).exportNameFormat = zQuery.GetString(NAME);
                }
                else if (typeof(ProjectLayout) == typeObj)
                {
                    var zProjectLayout = ((ProjectLayout)treeView.SelectedNode.Tag);
                    zProjectLayout.exportNameFormat            = zQuery.GetString(NAME);
                    zProjectLayout.exportRotation              = int.Parse(zQuery.GetString(ROTATION));
                    zProjectLayout.exportWidth                 = int.Parse(zQuery.GetString(EXPORT_WIDTH));
                    zProjectLayout.exportHeight                = int.Parse(zQuery.GetString(EXPORT_HEIGHT));
                    zProjectLayout.exportTransparentBackground = zQuery.GetBool(EXPORT_TRANSPARENT);
                    zProjectLayout.exportPDFAsPageBack         = zQuery.GetBool(EXPORT_PDF_AS_PAGE_BACK);
                }
                ProjectManager.Instance.FireProjectUpdated(true);
            }
        }